Jump to content

Archived

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

jaymc

Image stuff

Recommended Posts

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

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

I basically need to do something like this

[b]<img src="$thumb">[/b]

But obviously it doesnt work like that. Any help?

Thanks

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
How would that work?

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

[code]<?
// 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>";

?> [/code]

Share this post


Link to post
Share on other sites
Sorry, I see what you mean, just didnt want to have it as 2 different pages

But yeh, its working fine :)

Thanks

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Do you mean some clown had an image called bozo.gif and renamed it real_bozo.jpg?

http://ca.php.net/manual/en/function.getimagesize.php returns an array. The second index is the real file type regardless of the file extension.

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

Share this post


Link to post
Share on other sites
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?

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.