Jump to content


Photo

Image JPG/GIF


  • Please log in to reply
7 replies to this topic

#1 jaymc

jaymc
  • Members
  • PipPipPip
  • Advanced Member
  • 1,521 posts
  • LocationLiverpool

Posted 27 September 2006 - 11:08 PM

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?
I would love to change the world, but they won't give me the source code

SEO Agency

#2 brendandonhue

brendandonhue
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts

Posted 27 September 2006 - 11:11 PM

Are you using imagecreatefromjpeg()? You need to use imagecreatefromgif() if you want to load a GIF image.

#3 jaymc

jaymc
  • Members
  • PipPipPip
  • Advanced Member
  • 1,521 posts
  • LocationLiverpool

Posted 28 September 2006 - 12:01 AM

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
I would love to change the world, but they won't give me the source code

SEO Agency

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,016 posts

Posted 28 September 2006 - 12:22 AM

Perhaps if you posted some code we wouldn't have to guess what's wrong.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 jaymc

jaymc
  • Members
  • PipPipPip
  • Advanced Member
  • 1,521 posts
  • LocationLiverpool

Posted 28 September 2006 - 12:29 AM

<?
// 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);
?>

I would love to change the world, but they won't give me the source code

SEO Agency

#6 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,016 posts

Posted 28 September 2006 - 12:46 AM

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
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#7 jaymc

jaymc
  • Members
  • PipPipPip
  • Advanced Member
  • 1,521 posts
  • LocationLiverpool

Posted 28 September 2006 - 11:21 AM

Great, Ive got it working using the following approach
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);}

However, their is no imagecreatefrombmp

How do I handle bmp images?
I would love to change the world, but they won't give me the source code

SEO Agency

#8 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,016 posts

Posted 28 September 2006 - 11:42 AM

Not supported by GD. But if you want to process them

http://www.fortuneci...4/bmpffrmt.html
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users