gd - Crop image in PHP -


The code below is cropped properly, which I want, but for larger images, this work Also does well, is there any way of 'zooming through the image'

Moderation I can explain every image in almost the same shape before the crop so that every time I get good results

< P> The code is

  & lt ;? Php $ image = $ _GET ['src']; // crop the image $ dest_image = 'images / cropped_whatever.jpg'; // Make sure the directory is writable $ img = imagecreatetruecolor ('200', '150'); $ Org_img = imagecreatefromjpeg ($ image); $ Ims = getimagesize ($ image); Imagecopy ($ IMG, $ ORG_img, 0, 0, 20, 20, 200, 150); Imagejpeg ($ img, $ dest_image, 90); Imagedestroy ($ img); Echo '& lt; Img src = "'. $ Dest_image." "& Gt; & Lt; P & gt; '; If you are trying to generate thumbnails, you first have to resize the image using   

> imagecopyresampled (); . You should resize the image so that the size of the small edge of the image is equal to the corresponding side of the organ.

For example, if your source image is 1280x800px and your thumb is 200x150px, then you should change your image to 240x150px and then crop it to 200x150px. This is because the aspect ratio of the image will not change.

Here's a general formula for creating thumbnails:

  $ image = imagecreatefromjpeg ($ _GET ['src']); $ Filename = 'picture / cropped_whatever.jpg'; $ Thumb_width = 200; $ Thumb_height = 150; $ Width = imagesx ($ image); $ Height = images ($ image); $ Original_aspect = $ width / $ height; $ Thumb_aspect = $ thumb_width / $ thumb_height; If ($ original_aspect & gt; = $ thumb_aspect) {// if image thumbnail (in aspect ratio mean) is more than $ new_height = $ thumb_height; $ New_width = $ width / ($ height / $ thumb_height); } Else {// if thumbnail image is more than $ new_width = $ thumb_width; $ New_height = $ height / ($ width / $ thumb_digit); } $ Thumb = imagecreatetruecolor ($ thumb_width, $ thumb_height); // Image resize and crop image splashplay ($ thumb, $ image, 0 - ($ new_width - $ thumb_width) / 2, // Image horizontally image center - 0 - ($ new_height - $ thumb_height) / 2, 0, $ new_width, $ new_height, $ width, $ height); Imagejpeg ($ thumb, $ filename, 80);  

has not tested it but it should work.

Edit

Now test and work.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -