thumbnail height

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
d_cee
Regular
Posts: 603
Joined: Wed Jan 18, 2006 6:32 pm
Location: UK
Contact:

thumbnail height

Post 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
carl_galloway
Regular
Posts: 1331
Joined: Sun Dec 04, 2005 5:43 pm
Location: Andalucia, Spain
Contact:

Post 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.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
d_cee
Regular
Posts: 603
Joined: Wed Jan 18, 2006 6:32 pm
Location: UK
Contact:

Post 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
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
d_cee
Regular
Posts: 603
Joined: Wed Jan 18, 2006 6:32 pm
Location: UK
Contact:

Post 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
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post 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.
Judebert
---
Website | Wishlist | PayPal
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post 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.
Judebert
---
Website | Wishlist | PayPal
d_cee
Regular
Posts: 603
Joined: Wed Jan 18, 2006 6:32 pm
Location: UK
Contact:

Post 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
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post 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.
Judebert
---
Website | Wishlist | PayPal
Post Reply