1

Possible Duplicate:
Resize a picture to a fixed size

How to resize an image in PHP?

Community
  • 1
  • 1
DEVOPS
  • 18,190
  • 34
  • 95
  • 118
  • possible duplicate of [Resize a picture to a fixed size](http://stackoverflow.com/questions/747101/resize-a-picture-to-a-fixed-size) and many others – Gordon Jun 09 '10 at 10:31
  • Hi sir if the uploaded file is less size than we have to resize what will do. I need fixed size images. if uploaded image is bigger or smaller I have to make it as a constat size. – DEVOPS Jun 09 '10 at 12:33

6 Answers6

5

Try the GD and Image functions, or - if you want something more than just that - a library like ImageMagick.

Peter Kruithof
  • 10,584
  • 6
  • 29
  • 42
3

You may use imagemagick, call it via exec("convert ...") from php, copy it to the desired location and access it.

Thariama
  • 50,002
  • 13
  • 138
  • 166
  • Good suggestion, I've also used it. Requires exec() access for PHP though and many virtual hosting companies have denied it. – Ain Tohvri Jun 09 '10 at 10:34
  • 2
    ImageMagick offers a PHP API so there is no need for a less secure `exec()`: http://www.imagemagick.org/script/api.php?ImageMagick=bi9l24vaisg19eu5racue3gsh6#php – Dirk Vollmar Jun 09 '10 at 10:35
  • 1
    Through PHP API you've got a memory cap that kicks in pretty fast esp. considering the low memory of virtually hosted sites and users uploading their 10 MP images. – Ain Tohvri Jun 09 '10 at 10:37
1

You can also do like I do and use a lightweight framework like flourishlib.com where everything is nicely wrapped in a class fImage, example from documentation:

// Saving as a 60 quality JPEG
$image2 = new fImage('./example.gif');
$image2->resize(250, 0);
$image2->saveChanges('jpeg', 60);

It will work with both GD and ImageMagick

Michael
  • 2,631
  • 2
  • 24
  • 40
0

I'm using Image_Transform PEAR package for it. A ready-made thing that's pretty solid at this task.

Ain Tohvri
  • 2,987
  • 6
  • 32
  • 51
0

You may use codeigniter framework which provides you a lot of tools, including image manipulation. Otherwize, the main idea is to:

Aif
  • 11,015
  • 1
  • 30
  • 44
0

Here is the code to a Image resize script which i wrote a while back. It resizes the image and keeps the aspect ratio.

This script uses the core GD library to resize. So hopefully your host already got it installed.

I did some fast translation on the documentation from swedish to english. So it might not be perfect.

Hope it works!

hellozimi
  • 1,858
  • 19
  • 21