Convert image types

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Zamees
Forum Newbie
Posts: 19
Joined: Mon Oct 06, 2003 11:27 am

Convert image types

Post by Zamees »

How do I go about converting .bmp and .GIF to .jpg

What kinda PHP tricks can i do?
User avatar
mrvanjohnson
Forum Contributor
Posts: 137
Joined: Wed May 28, 2003 11:38 am
Location: San Diego, CA

Post by mrvanjohnson »

Can you give us an example of how you would use this? Why would you want PHP to do this? Wouldn't be easier to just upload the image in whatever format you want?

You could always just have PHP change the extension but this wouldn't be really "converting" it.
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

You could probably use GD to do this but I'm not sure if it can use BMP files. It can use WBMP files but I'm not sure if that's the same or not.

Anyway here's an example.......

Code: Select all

<?php
$im = imagecreatefromgif($theImage);
imagejpeg($im, "images/converted.jpeg", 100);
?>
......might be worth checking out GD if your not sure how to use it.
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post by xisle »

this app could work also...

http://www.imagemagick.org/

here's an example system command on a Linux server, the app is very powerful for image manipulation.

this converts pdf to jpg and to 150 dpi.

Code: Select all

<?php
system("convert -density 150x150 pdf:$source jpg:$destination");
?>
Zamees
Forum Newbie
Posts: 19
Joined: Mon Oct 06, 2003 11:27 am

Post by Zamees »

The server I run on has imagemagik, so ill give that a try. The whole thing to this is that users upload their picture, and if its a bmp or a gif then i can't throw it into my resize script, so i'll need to convert first. Im fairly new to php, my site is written in ASP, with one php script hopefully, this works out well.
Zamees
Forum Newbie
Posts: 19
Joined: Mon Oct 06, 2003 11:27 am

Post by Zamees »

just outta curiousity, how do i go about running a system command on my page. Do I just type that code in like it is. So i'd do a

If fileextension = .pdf,

php code above

end if
evilMind
Forum Contributor
Posts: 145
Joined: Fri Sep 19, 2003 10:09 am
Location: Earth

Post by evilMind »

A good place to start is http://us2.php.net/manual/en/ref.image.php. Make sure to look at the imagecreatefrom* functions as that is the first function you should use to convert an image.
Post Reply