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?
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?