Jump to content


Photo

Image stuff


  • Please log in to reply
6 replies to this topic

#1 jaymc

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

Posted 18 September 2006 - 10:49 PM

Ok, Im just making a script that will make resized thumbnails to save on bandwidth..

Ive mastered the image creation, however, I need the image displayed with some HTML theirfor I cant use the 'setting headers' approach

<?
// File and new size
$filename = 'JMC.jpg';

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

// 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 basically need to do something like this

<img src="$thumb">

But obviously it doesnt work like that. Any help?

Thanks
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 18 September 2006 - 10:51 PM

You can send the Content-type header to tell the browser its a jpg. If that's in image.php, you could then do <img src="image.php"> in your HTML file.

#3 jaymc

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

Posted 18 September 2006 - 10:54 PM

How would that work?

See the ECHO at the bottom. It doesnt work...

<?
// File and new size
$filename = 'JMC.jpg';
//$percent = 0.5;

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

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

echo "<img src=image.php>";

?>

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

SEO Agency

#4 jaymc

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

Posted 18 September 2006 - 10:58 PM

Sorry, I see what you mean, just didnt want to have it as 2 different pages

But yeh, its working fine :)

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

SEO Agency

#5 jaymc

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

Posted 18 September 2006 - 11:23 PM

Ok Ive got a new problem

The script works fine, but, if the file is a gif it doesnt work

Note, when I say gif, its actually named file.jpg but the image is still a gif

Any way around it?
I would love to change the world, but they won't give me the source code

SEO Agency

#6 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 19 September 2006 - 12:19 AM

Do you mean some clown had an image called bozo.gif and renamed it real_bozo.jpg?

http://ca.php.net/ma...etimagesize.php returns an array. The second index is the real file type regardless of the file extension.

$x = getimagesize($img);
if ($x[2]!=2) {
    echo "Hey, that's not a jpg file";
    exit();
}

Legend has it that reading the manual never killed anyone.
My site

#7 jaymc

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

Posted 19 September 2006 - 02:24 PM

Yeh thats what I mean..

Images dont really need extensions. If you rename bozo.gif to bozo.jpg the image will still work

I just dont get why it doesnt work with the php image stuff

In my script when someone uploads an image it automatically gets renamed image.jpg regardless of the real file type

Any way around it?
I would love to change the world, but they won't give me the source code

SEO Agency




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users