easily image resize/crop php

By | January 23, 2015

easily image resize/crop php

today i talk about how you can easily resize your uploading image.

it use for your portfolio image and your photo gallery.

and your website open quickly no take load.

let’s go.

<?php  

$filename= “test.jpg”; list($w, $h, $type, $attr) = getimagesize($filename); $src_im = 

imagecreatefromjpeg($filename);  $src_x = ‘0’;   // begin x $src_y = ‘0’;   // begin y $src_w = 

‘200’; // width

 $src_h = ‘100’; // height $dst_x = ‘0’;   // destination x $dst_y = ‘0’;   // destination y

$dst_im = imagecreatetruecolor($src_w, $src_h); $white = imagecolorallocate($dst_im, 255, 

255, 255); imagefill($dst_im, 0, 0, $white);  imagecopy($dst_im, $src_im, $dst_x, $dst_y, 

$src_x, $src_y, $src_w, $src_h);  header(“Content-type: image/png”); imagepng($dst_im); 

imagedestroy($dst_im);

?>

 
 
In the example provided, the upper left 200px x 100px are shown.
 
you manually set where you want crop (width/height) easily .

and enjoy.

thanks.


Category: PHP

Leave a Reply

Your email address will not be published. Required fields are marked *