Hi I was wondering how I could possibly pull an image with GD using imagecreatefromjpeg() or something similar to it and then cut it off to certain dimensions. For emaple, if I wanted a 50x50 image I would want it to cut the image off and display the top left corner 50x50, instead of resizing the whole thing to 50x50. I appreciate any help, thanks.

    Hi, I have tried that function before and it has never worked for me. I set the headers, I set the function correctly, I display it correctly with imagejpeg(), but all it does is display the URL of the current page in HTML text. Here's what I have:

    header("Content-type: image/jpeg");
    $new_width = 300;
    $new_height = 150;
    $n_image = imagecreatetruecolor($new_width, $new_height);
    $o_image = imagecreatefromjpeg("image.jpg");
    list($width, $height) = getimagesize($o_image);
    imagecopyresampled($n_image, $o_image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
    imagejpeg($n_image);
    imagedestroy($n_image);
    imagedestroy($o_image);

    What I'm trying to do is, no matter the size, cut the image off to 300x150 without shrinking or stretching the image, just cutting it. I have GD installed, everything is up to date, that's not a prob cause I've been working with PHP GD for about 8 months. Thanks. (NOTE: I have also tried it without the image destroys, and one time with imagejpeg($n_image, null, 100); like shown on php.net with no luck)

      Well, now I got it to work, the problem was I was trying to get the size of an image object, when the correct format is getimagesize(src). Now that it works I realized it's the wrong function, it doesnt cut it... it just resizes it distorting the image. Anyone? Thanks.

        Make a new image using imagecreate with the size you want, and then copy the old image onto it using imagecopy.

        Then imagejpeg() the new image, and you have your image.

          Write a Reply...