Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I believe you need to set the x and y coordinates to <strong>crop</strong> an image. Try something like this. You might have to play with the <code>top</code> and <code>left</code> numbers until you get it where you want. Take note of the <code>imagecopyresized</code> line. Also here is a similar post with an identical answer <a href="https://stackoverflow.com/questions/4970466/php-cropping-image-with-imagecopyresampled?rq=1">PHP - cropping image with imagecopyresampled()?</a> You need to set the x and y parameters as noted below. BTW the answer was really easy to find. SO even provides related questions on the right hand side of the page where I found that other example for you. Cheers. </p> <pre><code> switch( $case ){ case 1: $top = 50; $left = 50; $newwidth= 100; $newheight= 100; break; case 2: $newheight= 100; $ratio= $newheight / $height; $newwidth= round( $width * $ratio ); break; case 3: $newwidth= 100; $ratio= $newwidth / $width; $newheight= $height * $ratio; break; } switch( $imgtype ){ case 'image/jpeg'; $img= imagecreatefromjpeg( $imgtemp ); $thumb= imagecreatetruecolor( $newwidth, $newheight ); imagecopyresized( $thumb, $img, 0,0,$left,$top, $newwidth, $newheight, $width, $height ); imagejpeg( $thumb, $thumb_path ); break; case 'image/png'; $img= imagecreatefrompng( $imgtemp ); $thumb= imagecreatetruecolor( $newwidth, $newheight ); imagecopyresized( $thumb, $img, 0,0,0,0, $newwidth, $newheight, $width, $height ); imagepng( $thumb, $thumb_path ); break; case 'image/gif'; $img= imagecreatefromgif( $imgtemp ); $thumb= imagecreatetruecolor( $newwidth, $newheight ); imagecopyresized( $thumb, $img, 0,0,0,0, $newwidth, $newheight, $width, $height ); imagegif( $thumb, $thumb_path ); break; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload