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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.