How to restrict thumbnail size by width?

ChrisAllan

Joined: 2008-10-02
Posts: 10
Posted: Mon, 2008-10-06 16:02

Hi,

I'm new to gallery (using v2.2.6) but as far as I can see there is no way to restrict the size of the thumbnails specifically by WIDTH.

There is the option to specify a single parameter for the max size of the thumbnails - but this restricts whatever happens to be the larger dimension of width and height. I however don't care about the height, it is only the max WIDTH I wan't to specify.

To me this would seem like a common requirement. Am I being stupid, or is there a way to achieve this (whether it be simple, or implementing a hack).

Thanks for any help,

Chris

Login or register to post comments
alecmyers

Joined: 2006-08-01
Posts: 1839
Posted: Mon, 2008-10-06 16:04

Just curious...is there a really good reason why about every other question (including this one) gets posted four, five or more times identically? I've deleted four duplicates - is there a problem with the GMC software?

Login or register to post comments
floridave
floridave's picture

Joined: 2003-12-22
Posts: 11717
Posted: Mon, 2008-10-06 16:15
Quote:
- is there a problem with the GMC software?

Yes the breadbrumbs are not working right. Valiant and Bharat are working on a solution.

Quote:
but this restricts whatever happens to be the larger dimension of width and height.

That is by design. There is a few threads in the forums about this and perhpas there is a solution on one of them.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

Login or register to post comments
ChrisAllan

Joined: 2008-10-02
Posts: 10
Posted: Mon, 2008-10-06 16:29

I just find it really strange that software as sophisticated as Gallery doesn't easily allow you to restrict by width.

... anyone with suggestions on how this can be achieved - would love to hear it!

Login or register to post comments
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 4353
Posted: Mon, 2008-10-06 19:14

This may or may not be what you're looking for, but have you looked at the square thumbnails plugin?
http://codex.gallery2.org/Gallery2:Modules:squarethumb

It makes all thumbnails square. It's what I use because it makes a more uniform look to everything.
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

Login or register to post comments
ChrisAllan

Joined: 2008-10-02
Posts: 10
Posted: Mon, 2008-10-06 20:10

Thanks, but that's not really what I'm after. I want to maintain the original image ratio, and have a specified max width. I don't mind modifying core files to achieve this - I want exactly this behaviour throughout the entire site, so don't care if I lose the current default behaviour. Also I won't be applying (m)any updates to the gallery software, so any core changes shouldn't get overwritten.

Login or register to post comments
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 4353
Posted: Mon, 2008-10-06 20:54

I advise you to at least stay current with security fixes, though you should be able to just apply update files instead of overwriting your entire install.

Not a solution, but so far I've found this:
http://gallery.menalto.com/node/61155

mindless wrote:
you'd have to modify whichever image toolkit you use (imagemagick, etc) to support this behavior.

Ah and I think this one might be the solution:
http://gallery.menalto.com/node/54623
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

Login or register to post comments
ChrisAllan

Joined: 2008-10-02
Posts: 10
Posted: Mon, 2008-10-06 21:31

Hi,

Thanks for that. I have done something similar (though slightly different) to what is suggested in the last link.

in the file ImageMagickToolkit.Class, around line 140 where the code reads:
this->_addResizeParam($transform, $parameters[0]);

I have changed this to:
this->_addResizeParam($transform, $parameters[0], 1000);

My thumbnails are now resizing to the width I want, and ignoring the height.

Login or register to post comments
ChrisAllan

Joined: 2008-10-02
Posts: 10
Posted: Tue, 2008-10-07 19:48

Incase this is of interest to anyone else, I have also found a way to make the maxSize parameter in the g->image tag act as 'maxWidth' (this does not involve any acutal image resizing which is why this isn't achieved in any imageMagick hacks. This is just related to the width and height attributes that are included with the image).

In the file GalleryUtilities.class, in the function scaleDimensionsToFit:
change:
if ($aspect < $targetHeight / $targetWidth) {
$width = (int)$targetWidth;
$height = (int)round($targetWidth * $aspect);
} else {
$width = (int)round($targetHeight / $aspect);
$height = (int)$targetHeight;
}

to:
$width = (int)$targetWidth;
$height = (int)round($targetWidth * $aspect);

i.e. targetHeight is ignored, and only targetWidth is considered.

Login or register to post comments