How to resize jpg file by PHP?
16,827
Solution 1
try the imagecopyresampled
PHP function or the imagecopyresized
function from the GD library.
Solution 2
Basically using GD is pretty easy 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);
Again check the blog for details.
Author by
Mask
Updated on June 05, 2022Comments
-
Mask almost 2 years
It's now 925*1139,I want to change it to 90*110.
-
Patrice Bernassola over 14 yearsThe first one, as its name indicates, resampled while resizing for a better result. The second one only resize.