Jump to content

Recommended Posts

I've used this to automatically generate thumbnail images - works very well - just upload the original image, and it can be redrawn as a thumbnail, most importantly retaining it's original ratio. So far, so good.

However - and it may be in part due to the nature of the detail in the images - the thumbnails are suffering in quality - looking as tho' they have been sharpened way too much.

If you look here, you can see what I mean :

[URL=http://www.oriental-chamber.co.uk/persian.php]thumbnails [/URL]

Does anyone know if and how these images can be improved at all?

Cheers,
Iain
Link to comment
https://forums.phpfreaks.com/topic/30625-gd-image-library-thumbnail-quality/
Share on other sites

This is the code - I can't take credit for it - I found it when looking up GD, and it was then modified by someone else interested in doing the same thing.

[code=php:0]
<?php
// Max Sizes
$th_max_width = 96;  // Maximum width of the thumbnail
$th_max_height = 144; // Maximum height of the thumbnail

//-------------------

// File
$filename = $_GET['file'];

// Content type
header('Content-type: image/jpeg');

// Get image sizes
list($width, $height) = getimagesize($filename);

// Resize
$ratio = ($width > $height) ? $th_max_width/$width : $th_max_height/
$height;
$newwidth = round($width * $ratio);
$newheight = round($height * $ratio);

// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);

//Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, 
$width, $height);

// Output
imagejpeg($thumb);
?>

<?php
exit;
?>
[/code]
I think you're probably better using [url=http://uk.php.net/manual/en/function.imagecopyresampled.php]imagecopyresampled()[/url] as opposed to [url=http://uk.php.net/manual/en/function.imagecopyresized.php]imagecopyresized()[/url].

Regards
Huggie
@Huggie - yeah you're right. imagecopyresized can be quite hit and miss in terms of quality as it doesnt do anything further on the resulting image to 'smooth things out'.

if that doesnt sort out your problem, then [url=http://www.php.net/imagejpeg]imagejpeg[/url] has a third parameter, quality, which defaults to 75 (which is normally always adequate and pretty much standard): imagejpeg($image, '', 80);

cheers
Mark
Brilliant! I haven't tried it on the rug images (that's a project I'm working on at home), but I'm also working on a project here with more general photos, and that's made them noticably clearer, so will hopefully make the rug images more acceptable without having to resort to any manual prepping.

Glad it was a straightforward one!

Cheers,
Iain
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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