Page 1 of 1
thumbnail height
Posted: Thu Nov 09, 2006 12:35 am
by d_cee
Hi
in my configuration I can set the max width of the GD generated thumbnail. I'd like to change this so that I can set a max height instead.
Any help gratefully received

thanks
Dave
Posted: Thu Nov 09, 2006 2:41 am
by carl_galloway
It should be possible to edit the Serendipity file that handles the GD and change this so that it automatically uses height instead, or even both, but you'll need to find the code in one of the function files. I remember when I was trying to learn php a few months ago coming across the gd library and I know that your php file can pass all sorts of parameters to GD, its incredibly powerful.
Posted: Thu Nov 09, 2006 10:07 am
by garvinhicking
Hi!
Actually the thumbnail size will restrict an images width OR height, whatever is larger than the limit.
So it does not mean you specify the maximum width with it, really, and thus it would mean a complete code refactoring to make it choose maximum width AND height. Maybe you can live with the current approach of the "largest offender"?
Best regards,
Garvin
Posted: Thu Nov 09, 2006 11:18 am
by d_cee
Hi Garvin
the width dimension is unimportant for the site I'm working on. To make the layout work all the image thumbs in the media manager need to be the same height. I was hoping I could just swap width for height somewhere in the code. If not, how would it be if I made my own thumbs to the size I want, then uploaded them renamed 'filename.serendipityThumb.ext' as the media manager does?
cheers
Dave
Posted: Thu Nov 09, 2006 11:40 am
by garvinhicking
Hi!
But you should be able to simply set the thumbnail dimension s9y config item to the maximum height you want, and that should work? Of course your images would need to have the right aspect ratio, so s9y can't make tham all the same height if their width is different.
Of course you can upload your own image thumbnails, that's no problem. Just bear in mind that "Sync thumbnails" click will overwrite your thumbnails because of mismatching dimensions...
Best regards,
Garvin
Posted: Thu Nov 09, 2006 11:57 am
by d_cee
Hi Garvin
I figured if I rotated my images before uploading them so that the aspect ratios were the same and then rotated them back in the media manger this might work too, but because the site I'm working on is for an art gallery there's a hell of a lot of images
Making my own thumbs would be the best way forward but the gallery people want to do updates themselves when the site is finished - which is why I've built it with Serendipity
cheers
Dave
Posted: Thu Nov 09, 2006 12:52 pm
by garvinhicking
Hi David!
What I forgot to mention is that you can create a s9y event plugin that can also create different thumbnails additional to the ones you already created (like 'serendipityThumb2'). That plugin might even replace the original thumbnail.
Technically that's quite specific though, and would also take some time to code...
Best regards,
Garvin
Posted: Thu Nov 09, 2006 4:34 pm
by judebert
Or...
edit includes/functions_images.inc.php. Find the serendipity_resize_image_gd function. Replace the call to serendipity_calculate_aspect_size with your own:
Code: Select all
// $newwidth holds the configured max size
if ($height > $newwidth) {
// Force thumbnail height to configured max size
$newheight = $newwidth;
// Combine aspect calculation (newwidth / height) with scaling to
// provide greatest possible integer precision
$newwidth = ($width * $newwidth) / $height
}
I can't find any other places where resize is called with only a single dimension parameter. And this would be overwritten if you ever update. But it should work for the thumbnails.
Posted: Thu Nov 09, 2006 4:39 pm
by judebert
Ooh! If I'm wrong, and that code is used elsewhere, just put back the original code and go to the serendipity_makeThumbnail function. Find the serendipity_resize_image_gd call, and put my aspect-width-calculating code before the call like this:
Code: Select all
if ($serendipity['magick'] !== true) {
// $size holds the configured max size
if ($height > $size) {
// Force thumbnail height to configured max size
$newheight = $size;
// Combine aspect calculation (size / height) with scaling to
// provide greatest possible integer precision
$newwidth = ($width * $size) / $height
$r = serendipity_resize_image_gd($infile, $outfile, $newwidth, $newheight);
}
}
In fact, I recommend this modification instead. It assumes you don't want to resize images that are less than the max height, no matter what their width; and it ONLY affects the thumbnail code.
Posted: Fri Nov 10, 2006 12:03 am
by d_cee
Hi Jude
thanks for this. I gave it a try and couldn't get it to change the height. There was a ; missing which threw me at first as I was getting an error but after I noticed it was missing I got no errors - and no result
Then I thought I should make $height = 100; this being my desired height. Still no result.
I pm'd Garvin about this earlier too and he's trying to make something work for. I'll let you know how it works out before you spend any more time on this.
thanks
Dave
Posted: Fri Nov 10, 2006 3:45 am
by judebert
Oh, criminy. Sorry about the missing semicolon. I'm no Garvin.
This would only work if your Serendipity is set to GD, not ImageMagick. We'd need some other magic for ImageMagick.
I'm sorry to have loaded extra work on you, Garvin. I could always put this stuff on one of my test blogs if you want me to take it over again.