Jump to content

Image stuff


jaymc

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
Link to comment
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]
Link to comment
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]
Link to comment
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?
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.