imagejpeg not working on production server

634 Views Asked by At

I have the following function in WordPress that grabs pictures of all the users in a group, stitches them together and creates a composite image which it then saves in the theme folder.

This works perfectly on my development server, but does nothing on the production server.

Is this a permissions issue? Development server is running php 5.5.12 and live server is running 5.5.23 so that shouldn't cause an issue (I don't believe imagejpeg has been deprecated?). Both are running the most recent version of WordPress. Development server is WAMP, production server is LAMP.

Function below:

function group_thumbnail($post_id) {

        // Generates a composite thumbnail, a la Spotify playlists, to use in the group layout.

                $user_portraits = array();
                if(!empty($_POST['wpcf']['allowed-users'])) :
                    $allowed_users = $_POST['wpcf']['allowed-users']; // For the back end
                else : 
                    $allowed_users = get_post_meta($post_id,'wpcf-allowed-users',false); // For the front end
                endif;

                $allowed_users = sort_pictures_by_name($allowed_users);

                $group_size = count($allowed_users);

                if($group_size < 4) : $limit=1; $row_size = 1; endif;
                if($group_size >= 4 && $group_size < 9) : $limit=4; $row_size = 2; endif;
                if($group_size >= 9 && $group_size < 16) : $limit=9; $row_size = 3; endif;
                if($group_size >= 16) : $limit=16; $row_size = 4; endif;
                $square_size = 200/$row_size;
                foreach ($allowed_users as $u_id) :
                    $u_portrait=get_user_meta($u_id, 'wpcf-portrait', true); 
                    $u_file = imagecreatefromjpeg($u_portrait);
                    $user_portraits[] = $u_file;
                endforeach;
                $group_image = imagecreatetruecolor ( 200 , 200 );
                $postion = array('x'=>0,'y'=>0);
                for($i=0; $i<$limit; $i++) :    
                    if($i % $row_size == 0 && $i<>0) : 
                        $postion['x']=0;
                        $postion['y']+=$square_size;
                    endif;  
                    imagecopyresized($group_image,$user_portraits[$i],$postion['x'],$postion['y'],0,0,$square_size,$square_size,180,180);
                    imagedestroy($user_portraits[$i]);
                    $postion['x']+=$square_size;
                endfor;         
                // Output and free from memory
                imagejpeg($group_image,get_template_directory().'/img/groups/'.$post_id.'.jpg',60);
                imagedestroy($group_image);
                clearstatcache();

    }
1

There are 1 best solutions below

0
On BEST ANSWER

It was pretty simple in the end - the folder on the production server wasn't writable. Quickly sorted out via FTP.