Jump to content

Recommended Posts

hi there!

My problem is the following. I am trying to write a function that will cut out a fixed-size piece from the CENTER of an uploaded picture.

However, my function seems to always cut out a piece from the bottom right corner of the image (filling the difference with black), although the image itself is rather large and the coordinates are given.

Thanks in advance! Here's the code!

 

    function CreateThumb($filename) {
        
        $source = imagecreatefromjpeg($filename);
        
        $width = imagesx($source);
        $height = imagesy($source);
        
        $output_width = 215;
        $output_height = 212;
        
        $center_hor = $width/2;
        $center_vert = $height/2;
        
        $src_x = $center_hor - $output_width/2;
        $src_y = $center_vert + $output_height/2;
        
        $output = imagecreatetruecolor($output_width, $output_height);
        imagecopyresampled($output, $source, 0, 0, $src_x, $src_y, $output_width, $output_height, $width, $height);
        $new = basename($filename);
        imagejpeg($output, dirname($filename).'/tn'.$new, 100);
        imagedestroy($source);
        imagedestroy($output);
        }
    }

Link to comment
https://forums.phpfreaks.com/topic/67135-cut-out-picture/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.