Click to See Complete Forum and Search --> : THUMBS -> imageXXX / header ("Content-type: mime_type");


rogernem
October 27th, 2009, 12:03 PM
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.


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:


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?

PeejAvery
October 27th, 2009, 12:18 PM
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
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);
?>

rogernem
October 27th, 2009, 01:27 PM
It worked. Thanks.