How to scale down an image on the server side with PHP? -



How to scale down an image on the server side with PHP? -

i have images pulled server , $imgurl holds path of image.

right utilize <img src="<?php echo $imgurl ?>" width="100" height="200"/> or css scale downwards image, want in php serve scaled images dom

any ideas?

thanks

this solution cause thumb created when requested first time. future requests fetch created thumb. using imagemagick:

html:

<img src="script.php?img=example" />

php (script.php):

$width = 140; $height = 80; $image = $_get['img']; $ext = 'png'; // check if file exists if ( ! file_exists('/path/to/the/'.$image.'.'.$ext)) { die('unable process requested file.'); } // check if thumb exists, otherwise create thumb if (file_exists('/path/to/the/'.$image.'_thumb.'.$ext)) { $img = new imagick('/path/to/the/'.$image.'_thumb.'.$ext); } else { $img = new imagick('/path/to/the/'.$image.'.'.$ext); $img->setimageformat($ext); $img->scaleimage($width, 0); $img->cropimage($width, $height, 0, 0); $img->writeimage('/path/to/the/'.$image.'_thumb.'.$ext); } // homecoming image header('content-type: image/'.$ext); echo $img;

php image-processing scale image-resizing

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -