THUMBS -> imageXXX / header ("Content-type: mime_type");
I have images in my server and I´d like to "create" thumbnails.
I tried to resize the image but it appears blured and strange.
I want to do that then because the image looks perfect when I do it.
Code:
function Thumb($photo, $new_width)
{
$source = imagecreatefromstring(file_get_contents($photo));
$thumb = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
header ("Content-type: image/jpeg");
imagejpeg("my_resized_img.jpg");
}
Thumb("images/pic139.jpg",150);
When I run the code it works perfectly but JUST FOR ONE IMAGE (pic139.jpg).
But what I want to do is that for all the images displayed in the page.
Something like this:
Code:
Thumb("images/pic139.jpg",150);
Thumb("images/pic140.jpg",150);
Thumb("images/pic141.jpg",150);
etc...
How can I do that without having to create the thumbnail?
The problem that I see is with the header ("Content-type: image/jpeg");
Any ideas?
Re: THUMBS -> imageXXX / header ("Content-type: mime_type");
Rather than ask a bunch of questions, just try using the following instead. Name it thumbnail.php and pass path and width as parameters.
PHP Code:
<?php
header('Content-type: image/jpeg');
$path = @$_GET['path'];
$img_source = imagecreatefromjpeg($path);
list($width, $height) = getimagesize($path);
$new_width = @$_GET['width'];
$new_height = ($height / $width) * $new_width;
$img_output = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($img_output, $img_source, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagejpeg($img_output, "", 100);
imagedestroy($img_output);
imagedestroy($img_source);
?>
Re: THUMBS -> imageXXX / header ("Content-type: mime_type");