How can I convert a single jpg image into 3 different image formats, gif, png and bmp, using PHP?
Asked
Active
Viewed 4.3k times
21
-
1Surely 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 Answers
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
-
6Note that WBMP is not the BMP as you might know it: http://en.wikipedia.org/wiki/Wbmp – Evert May 17 '09 at 17:23
-
2
-
How do I get a `bmp`? Since wbmp is not bmp, so image viewer in ubuntu says bogus data. – prongs Jan 06 '12 at 09:19
5
Use libGD — http://www.php.net/manual/en/book.image.php

vartec
- 131,205
- 36
- 218
- 244
-
2But 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