How to resize jpg file in PHP?

It is now 925 * 1139, I want to change it to 90 * 110.

+2


source to share


4 answers


+6


source


Basically using GD is pretty straightforward once you know what to do.

$uploadedfile = $_FILES['file']['tmp_name']; 
$src = imagecreatefromjpeg($uploadedfile);        
list($width, $height) = getimagesize($uploadedfile); 

$tmp = imagecreatetruecolor(800, 600); 

$filename = '/path/to/images/' . $_FILES['file']['name'];

imagecopyresampled($tmp, $src, 0, 0, 0, 0, 800, 600, $width, $height); 
imagejpeg($tmp, $filename, 100);

      



Check the blog again for details.

+3


source


Here you can change a class called SimpleImage. Or take a look at the source and see how they solve the problem:

SimpleImage code

0


source


I haven't done PHP in a while (why am I even in this tag?), But you should check out GDLib. iirc, it's better integrated than imagemagick.

http://php.net/manual/en/book.image.php

0


source







All Articles