开发者

How to resize jpg file by PHP?

开发者 https://www.devze.com 2022-12-09 16:46 出处:网络
It\'s now开发者_Go百科 925*1139,I want to change it to 90*110.try the imagecopyresampled PHP function or the imagecopyresized function from the GD library.Basically using GD is pretty easy once you kn

It's now开发者_Go百科 925*1139,I want to change it to 90*110.


try the imagecopyresampled PHP function or the imagecopyresized function from the GD library.


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.


here's a resizing class called SimpleImage that you can use. Or take a look at the source and see how they tackle the problem:

SimpleImage Code


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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号