Solved

How to convert gif to jpg

Posted on 2006-11-04
4
297 Views
Last Modified: 2008-02-01
Hi

I upload gifs which I want to convert and save as jpgs. I do this:

...
$image = @imagecreatefromgif($filename);
if($image)
{
  $image_p = imagecreatetruecolor($new_width, $new_height);
  imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  imagejpeg($image_p, $filename_tn, 100); // 100% quality
}

Will that do the job, or is something else needed?

Thanks
tr5
0
Comment
Question by:tr5
  • 2
  • 2
4 Comments
 
LVL 35

Accepted Solution

by:
Raynard7 earned 500 total points
Comment Utility
Hi,  that should be sufficient

the colour looks right, the conversion looks right and saving the jpeg looks right.

The only thing I would consider is if you are uploading these to be converted - why not convert the $_FILE to a jpeg on the fly rather than saving the gif to file and then re sampling it?
0
 

Author Comment

by:tr5
Comment Utility
How would I do that?
0
 
LVL 35

Expert Comment

by:Raynard7
Comment Utility
well - you have $image

= imagecreatefromgif($filename)

you should just be able to point it to the uploaded file

= imagecreatefromgif($_FILE['uploadedFileName']);

and the rest of the script would remain the same
0
 

Author Comment

by:tr5
Comment Utility
ok. Thanks.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now