Jump to content

Image JPG/GIF


jaymc

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?
Link to comment
https://forums.phpfreaks.com/topic/22311-image-jpggif/
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]
Link to comment
https://forums.phpfreaks.com/topic/22311-image-jpggif/#findComment-99972
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?
Link to comment
https://forums.phpfreaks.com/topic/22311-image-jpggif/#findComment-100168
Share on other sites

Archived

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

×
×
  • Create New...

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.