Jump to content

Archived

This topic is now archived and is closed to further replies.

jaymc

Image JPG/GIF

Recommended Posts

I have an upload script that allows people to upload images, adds a bit of text on the image then displays it

This works great, but, here is the problem

It only works if the file was saved as a JPG!

If the image the upload is a gif, then the image does not display. My script needs to support atleast jpeg, gif bmp & png

Obviously imagejpeg() does not support anything other than true jpg files

Any way around it / alternitives?

Share this post


Link to post
Share on other sites
well the problem is, the gif files are saved as .jpg

So they are true gif files but named file.jpg, so I cant determine if they are gif or not as I cant go by the file extension

Share this post


Link to post
Share on other sites
[code]<?
// File and new size
$userpic = $_GET['user'];
$filename = "pics/".$userpic.".jpg";


// Content type
header('Content-type: image/jpeg');

  // Date in the past, so that the image is not cached by the browser
Header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = 76;
$newheight = 62;

// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);

// Resize
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);


// Output
imagejpeg($thumb, null, 100);
?> [/code]

Share this post


Link to post
Share on other sites
getimagesize() will also tell you the type of the file

list($width, $height, $type) = getimagesize($filename);

Use the type info to adjust your code accordingly

Share this post


Link to post
Share on other sites
Great, Ive got it working using the following approach
[code]if ($type[2] == 1) {$source = imagecreatefromgif($filename);}
else if ($type[2] == 2) {$source = imagecreatefromjpeg($filename);}
else if ($type[2] == 3) {$source = imagecreatefrompng($filename);}
else if ($type[2] == 4) {$source = imagecreatefromjpeg($filename);}
else if ($type[2] == 6) {$source = imagecreatefrombmp($filename);}[/code]

However, their is no [b]imagecreatefrombmp[/b]

How do I handle bmp images?

Share this post


Link to post
Share on other sites
Not supported by GD. But if you want to process them

http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.