21

How can I convert a single jpg image into 3 different image formats, gif, png and bmp, using PHP?

Solomon Ucko
  • 5,724
  • 3
  • 24
  • 45
riad
  • 7,144
  • 22
  • 59
  • 70
  • 1
    Surely you don't want to convert anything to BMP on the web. Non-animated GIF is a waste of bandwidth as well. – Kornel Dec 18 '11 at 15:50

3 Answers3

42

You first create an image object out of your file with imagecreatefromjpeg(). You then dump that object into different formats (using imagegif() for example):

$imageObject = imagecreatefromjpeg($imageFile);
imagegif($imageObject, $imageFile . '.gif');
imagepng($imageObject, $imageFile . '.png');
imagewbmp($imageObject, $imageFile . '.bmp');
soulmerge
  • 73,842
  • 19
  • 118
  • 155
5

Use libGD — http://www.php.net/manual/en/book.image.php

vartec
  • 131,205
  • 36
  • 218
  • 244
  • 2
    But its a huge library file, Could u pls help me for a perticular one? which code i have to use? – riad Apr 16 '09 at 12:02
2

I've set up a new opensource project on Github that allows reading and saving of BMP files (actual BMP files, not wbmp), and other file formats, in PHP. It's nice and easy to use.

The project is called PHP Image Magician.

Jarrod
  • 9,349
  • 5
  • 58
  • 73