Mask
Mask

Reputation: 34197

How to resize jpg file by PHP?

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

Upvotes: 2

Views: 18899

Answers (4)

Savas Vedova
Savas Vedova

Reputation: 5692

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.

Upvotes: 4

Patrice Bernassola
Patrice Bernassola

Reputation: 14426

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

Upvotes: 7

Oren Mazor
Oren Mazor

Reputation: 4477

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

Upvotes: 0

GSto
GSto

Reputation: 42350

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

Upvotes: 0

Related Questions