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
https://forums.phpfreaks.com/topic/21207-image-stuff/
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
https://forums.phpfreaks.com/topic/21207-image-stuff/#findComment-94281
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
https://forums.phpfreaks.com/topic/21207-image-stuff/#findComment-94322
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
https://forums.phpfreaks.com/topic/21207-image-stuff/#findComment-94654
Share on other sites

Archived

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

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