|
-
October 27th, 2009, 12:03 PM
#1
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?
-
October 27th, 2009, 12:18 PM
#2
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); ?>
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
October 27th, 2009, 01:27 PM
#3
Re: THUMBS -> imageXXX / header ("Content-type: mime_type");
Last edited by rogernem; October 27th, 2009 at 01:45 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|