Customized Gallery: Square Thumbnails

gerb

Joined: 2004-12-02
Posts: 5
Posted: Thu, 2004-12-02 15:35

Can anyone post the amended files to make square thumbs??? I've used these instructions a few times now - I've been really careful each time but something goes wrong. I agree, the files would be much easier...

Thanks : )

 
richbl

Joined: 2004-05-30
Posts: 43
Posted: Thu, 2004-12-02 22:30
tmothy wrote:
Rich your directions are beyond frustrating. Why not just provide the edited php files for the latest gallery. That or "on line 249 add XXXX"

Thanks for the kind words.

Unfortunately, it's not as easy as "just" posting updated files for two reasons:

--I don't maintain the code changes for each release of Gallery (they are too frequently released to update regularly)
--The files that I do maintain for my websites include significant modifications well beyond the scope of the square thumbnails mods.

For these reasons, the solution is to post changes in logic and note them for others to modify as appropriate in their own Gallery code. These changes are non-trivial, and I wouldn't consider them to be a strict "cut and paste" solution.

best of luck,

rich

 
gerb

Joined: 2004-12-02
Posts: 5
Posted: Wed, 2005-01-05 14:19
Quote:
Unfortunately, it's not as easy as "just" posting updated files

Can you let us decide that by supplying the files (those that you suggest we amend) as you have them :)

Even if it doesn't work for us initially, at least we can have a dabble knowing that they work for you - plus you'll get us off your back :)

Cheers...

 
richbl

Joined: 2004-05-30
Posts: 43
Posted: Wed, 2005-01-05 17:37
gerb wrote:
Quote:
Unfortunately, it's not as easy as "just" posting updated files

Can you let us decide that by supplying the files (those that you suggest we amend) as you have them :)

Even if it doesn't work for us initially, at least we can have a dabble knowing that they work for you - plus you'll get us off your back :)

Cheers...

gerb,

Per your request, I've attached a zip file of mods that include, but not limited to, square thumbnails.

As I've advised previously, however, be aware of the following:

--These files are based on Gallery v1.4.4-pl2. Using these files in Gallery installations other than v1.4.4-pl2 is not recommended
--These files are provided "as is" and include numerous changes that may or may not adversely affect your existing Gallery installation

I would further suggest that you review my previous posts which provide a thorough explanation of the logic behind each of the code changes. Having an accurate understanding of what has changed, and why, is a much safer approach to accepting mods made in Gallery.

rich

 
gerb

Joined: 2004-12-02
Posts: 5
Posted: Wed, 2005-01-05 17:43

Thanks richbl - will give them a go. :)

 
beaster

Joined: 2003-12-31
Posts: 11
Posted: Sun, 2005-01-23 22:02
richbl wrote:
Hello all,

I've made a revision to my square thumbnail feature in Gallery v.1.4.4. The primary reason for doing this was to clean up the code logic while also providing some added flexibility in the use of the feature.

Perhaps the most significant improvement is the added capability of toggling square thumbnails via the Properties page.

As the complexity of this feature has increased, so too have the number of files affected. The list below is all files that must be altered in order to provide for the square thumbnails feature:

    \gallery\config.php
    \gallery\edit_appearance.php
    \gallery\util.php

    \gallery\classes\AlbumItem.php
    \gallery\classes\Album.php

As in previous posts, code commented with #### indicates changes in logic. While the feature has been tested using sources from Gallery v1.4.4, there should be no reason for the logic to propagate backwards (or forwards) through past or future Gallery releases.

....

First off, let me say thanks for all the work you put into this. I hadn't even thought of tackling this type of hack because I knew it was no simple thing.

I manually updated the files and everything worked on the first go. I want to tweak the crop position, but I'm happy I now getting square thumbs.

Not sure what the difficulty is for other folks here. Again, thanks. When I get my gallery finished and uploaded from my dev box, I'll post a link.[/]

 
harvey

Joined: 2005-01-28
Posts: 7
Posted: Fri, 2005-01-28 07:12

Rich,

I'm indebted to you. I'd been looking at doing something like this myself, and had been worrying about how I was going to implement it. What luck to find that someone had already done it, and more-than-likely much better than I could have done! Thank you.

I do have one question, and it's possibly/probably related to something that Shadow_Wolf had been asking. To clarify, though: What I was wanting to do was to resize the image to Thumbnail-size, then crop it from the center, as opposed to the top-left. This would give a better visual example of what the photo was focusing on via the thumbnail (since the subject would be closer to the center), and would maybe even be a little more aesthetically pleasing. It's essentially the same thing as what your hack does, only it would be cropping the longer sides off at the edges in order to make it a square.

Is there a way to do this that you can think of? Or, if my explanation is lacking, let me know. I'll see what I can do to clarify.

Again, thanks for all of your hard work.

H.

 
richbl

Joined: 2004-05-30
Posts: 43
Posted: Fri, 2005-02-18 21:10
harvey wrote:
Rich,

I'm indebted to you. I'd been looking at doing something like this myself, and had been worrying about how I was going to implement it. What luck to find that someone had already done it, and more-than-likely much better than I could have done! Thank you.

I do have one question, and it's possibly/probably related to something that Shadow_Wolf had been asking. To clarify, though: What I was wanting to do was to resize the image to Thumbnail-size, then crop it from the center, as opposed to the top-left. This would give a better visual example of what the photo was focusing on via the thumbnail (since the subject would be closer to the center), and would maybe even be a little more aesthetically pleasing. It's essentially the same thing as what your hack does, only it would be cropping the longer sides off at the edges in order to make it a square.

Is there a way to do this that you can think of? Or, if my explanation is lacking, let me know. I'll see what I can do to clarify.

Again, thanks for all of your hard work.

H.

Thanks very much for the compliments.

Regarding your question about a "centered" cropped thumbnail, yes, it's possible to do what you want. However, you need to think about how the current thumbnail routine works to better understand what it is that you're interested in doing.

The current logic first takes the original image and resizes it such that the shortest of either height or width does not fall below the minimum requirement for thumbnail size (I use 108px). Then, the image is simply cropped square. So, the final square thumbnail really depends on the height:width ratio of the originating image. To test this functionality, provide Gallery with images that are extreme in their dimensions: a perfectly square image, and an image that is very tall or very wide (panoramic image). You'll better understand from the results of these image croppings what exactly is happening.

Knowing this, to do what you'd like to do is very different. To produce a centered thumbnail image, you'd want to determine how to first resize the original image. If you didn't resize the original image, you would get a thumbnail that appears to be a "close-up" of the image (if an image is 1000px on a side, and a thumb is 100px, that's 10% of the image). Since images are dynamic in size, you'd really want to reduce by a percentage (50%?). Once resized, it would be fairly easy to find the centerpoint of an image and crop accordingly. So, in addition to providing the interface to the Gallery user for thumbnail size, you'd also want to provide a scaling value.

This would be a great option to add to this square thumbnail mod.

best of luck,

rich

 
harvey

Joined: 2005-01-28
Posts: 7
Posted: Sat, 2005-02-19 16:14
richbl wrote:
Thanks very much for the compliments.

Regarding your question about a "centered" cropped thumbnail, yes, it's possible to do what you want. However, you need to think about how the current thumbnail routine works to better understand what it is that you're interested in doing.

The current logic first takes the original image and resizes it such that the shortest of either height or width does not fall below the minimum requirement for thumbnail size (I use 108px). Then, the image is simply cropped square. So, the final square thumbnail really depends on the height:width ratio of the originating image. To test this functionality, provide Gallery with images that are extreme in their dimensions: a perfectly square image, and an image that is very tall or very wide (panoramic image). You'll better understand from the results of these image croppings what exactly is happening.

Knowing this, to do what you'd like to do is very different. To produce a centered thumbnail image, you'd want to determine how to first resize the original image. If you didn't resize the original image, you would get a thumbnail that appears to be a "close-up" of the image (if an image is 1000px on a side, and a thumb is 100px, that's 10% of the image). Since images are dynamic in size, you'd really want to reduce by a percentage (50%?). Once resized, it would be fairly easy to find the centerpoint of an image and crop accordingly. So, in addition to providing the interface to the Gallery user for thumbnail size, you'd also want to provide a scaling value.

This would be a great option to add to this square thumbnail mod.

best of luck,

rich

I was wanting to resize the thumbnails, though, too. Say the image was resized to your minimum required thumbnail size (in your case, 108px), and then the longer sides were cropped off from there. So if you had a final resized image of 162w x 108h, you would crop out those extra 54 pixels on the sides to make it square.

 
beaster

Joined: 2003-12-31
Posts: 11
Posted: Mon, 2005-02-28 00:06
richbl wrote:
In config.php:

...
/* Defaults */
$gallery->app->default["bordercolor"] = "black";
$gallery->app->default["border"] = "1";
$gallery->app->default["font"] = "arial";
$gallery->app->default["cols"] = "7";
$gallery->app->default["rows"] = "10";
$gallery->app->default["thumb_size"] = "108";

// ####
$gallery->app->default["thumb_shape"] = "no";

$gallery->app->default["resize_size"] = "off";
$gallery->app->default["resize_file_size"] = "0";
$gallery->app->default["max_size"] = "640";
$gallery->app->default["max_file_size"] = "0";
...

I noticed something interesting today. When running setup after editing config.php, the code modification gets erased in this file and I need to add it again.

I'm going to look into it some more, but if anyone has a quick answer, let me know.

EDIT: Found the problem. I added this code to config_data.inc in the setup dir:

	"group3" => array (
		"type" => 'group_start',
		"name" => 'group_display',
		"default" => 'none',
		"title" => _("Image Processing and Display")
	),
	"thumb_size" => array(
		"prompt" => _("Thumbnail size"),
		"desc" => _("The default target size (in pixels) of album thumbnails."),
		"value" => 150,
		"attrs" => array("size" => 10),
		"type" => "text"
	),

// BEGIN NEW CODE
	"thumb_shape" => array(
		"prompt" => _("Square thumbnails"),
		"desc" => _("Turn on square thumbnails."),
		"choices" => array("yes" => _("yes"), "no" => _("no")),
		"value" => "no",
	),
// END NEW CODE

	"resize_size" => array(
		"prompt" => _("Resized image size"),
		"desc" => _("When large images are added to an album, an intermediate version will automatically be generated at this size."),
		"value" => 640,
		"choices" => array("off" => _("off"), 400 => 400, 500 => 500, 600 => 600, 640 => 640, 700 => 700, 800 => 800, 1024 => 1024)
	),

 
fly.cub

Joined: 2005-03-31
Posts: 30
Posted: Mon, 2005-04-04 16:13

Hi Rich, first of thanks for your willingness to share your efforts.

I tried to manually change the code in the files following your directions. Unfortunately, I get the following error when I try to load Gallery :

Quote:
Parse error: parse error, unexpected T_IF in /home/severyn/public_html/gallery/util.php on line 496

I did chmod the following files/folders to 777 : .htaccess, config.php and setup.

FYI, I am using G1.5-RC2 (if anyone has this hack work on 1.5-RC2, it would help to know...).

Do you have any suggestion ?

Thanks again for your help.

Olivier

 
maledictus

Joined: 2005-03-08
Posts: 23
Posted: Thu, 2005-04-07 23:05

This modifies the first page thumbs (the first page loaded when you enter to the gallery) or the thumbs inside the albums (sub-albums or photos)?

 
fly.cub

Joined: 2005-03-31
Posts: 30
Posted: Fri, 2005-04-08 20:25

I'm not sure I understand your question : the hack is suppose to give the option of choosing square thumbs and/or square album thumbs.
But in my case, I can't even load Gallery ! I get the error as soon as I try to load the index page...
I removed the hack from my pages so I could keep working on other aspects of my custom Gallery, but I'm still looking for somebody willing to help with the square thumbs :)
Thanks.

 
maledictus

Joined: 2005-03-08
Posts: 23
Posted: Fri, 2005-04-08 21:12
fly.cub wrote:
I'm not sure I understand your question : the hack is suppose to give the option of choosing square thumbs and/or square album thumbs.
But in my case, I can't even load Gallery ! I get the error as soon as I try to load the index page...
I removed the hack from my pages so I could keep working on other aspects of my custom Gallery, but I'm still looking for somebody willing to help with the square thumbs :)
Thanks.

Hey man I used Rich (Thank you so much man) code in page two of this topic, the last post is the one im using and it works great for gallery 1.4.4. Hope it can help!

 
Terje-
Terje-'s picture

Joined: 2004-01-20
Posts: 90
Posted: Sat, 2005-04-09 00:39
fly.cub wrote:
I'm not sure I understand your question : the hack is suppose to give the option of choosing square thumbs and/or square album thumbs.
But in my case, I can't even load Gallery ! I get the error as soon as I try to load the index page...
I removed the hack from my pages so I could keep working on other aspects of my custom Gallery, but I'm still looking for somebody willing to help with the square thumbs :)
Thanks.

I don't think the code works for 1.5-cvs, I think there has been made a few changes to how the resize works (e.g recursive thumbnail generation, recursive resize, etc)..

If anyone makes this work for 1.5-cvs, please keep up updated. :-)

 
richbl

Joined: 2004-05-30
Posts: 43
Posted: Sat, 2005-04-09 16:29
maledictus wrote:
This modifies the first page thumbs (the first page loaded when you enter to the gallery) or the thumbs inside the albums (sub-albums or photos)?

This hack will mod image thumbnails and, optionally, "first page" gallery thumbs (see previous thread topics for details).

But, be advised that this mod is untested for any Gallery installation beyond v1.4.4-pl2. While the logic for creating and displaying square thumbnails will be the same, the code most certainly is not.

rich

 
richbl

Joined: 2004-05-30
Posts: 43
Posted: Sat, 2005-04-09 16:35
Terje- wrote:
fly.cub wrote:
I'm not sure I understand your question : the hack is suppose to give the option of choosing square thumbs and/or square album thumbs.
But in my case, I can't even load Gallery ! I get the error as soon as I try to load the index page...
I removed the hack from my pages so I could keep working on other aspects of my custom Gallery, but I'm still looking for somebody willing to help with the square thumbs :)
Thanks.

I don't think the code works for 1.5-cvs, I think there has been made a few changes to how the resize works (e.g recursive thumbnail generation, recursive resize, etc)..

If anyone makes this work for 1.5-cvs, please keep up updated. :-)

Yes, absolutely!

This mod is untested for any Gallery installation beyond v1.4.4-pl2. While the logic for creating and displaying square thumbnails will be the same, the code most certainly is not.

rich

 
richbl

Joined: 2004-05-30
Posts: 43
Posted: Sat, 2005-04-09 17:01

To all interested in the square thumbnail mod for Gallery,

I would first like to thank everyone for their kind words of thanks and encouragement for creating this modification to Gallery. I created square thumbnails as an exercise for me to better understand how Gallery worked. It was a lot of fun and a great learning experience.

As most folks here on this forum are aware, Gallery 2.0 is getting closer to completion, and it looks very promising indeed. Perhaps best of all, Gallery 2.0 will have native support for... square thumbnails!

To that end, I will not be making any further changes to the square thumbnail mod in Gallery 1.xx.

The last Gallery release that I have looked at and am familiar with is v1.4.4-pl2, which is the most recent version under which the square thumbnails mod has been tested.

If you are interested in using the square thumbnail mod for Gallery releases beyond v1.4.4-pl2, go for it! But, be aware that the mod may not work. While the logic for creating and displaying square thumbnails is the same, the underlying Gallery code most certainly is not.

As always, enjoy!

rich

 
zondi

Joined: 2005-04-13
Posts: 10
Posted: Tue, 2005-04-26 04:07

Good Evening,

Thank you so much for your contribs to this forum.

I have two quick questions if you have any chance to reply.

1st) I am struggling with getting any answer on how to set thumbnails, albums wide, to create as square (Version 1.5).

2nd) I would very much like my thumbs to NOT have any space between them. Instead of evenly spacing across a large space table, I'd like to reverse that and have them bunch together (much like you have shown on your referenced site)..

Thanks for any help!
:lol:

 
jmullan
jmullan's picture

Joined: 2002-07-28
Posts: 974
Posted: Fri, 2005-09-09 21:45

asdl hgvaljsdaksd hk;jsdh gfa;dshfhd

ARGH

This hack makes bad things happen to the thumbs during migration. Normal values are relative to the full sized image.

thumb_x 447
thumb_y 340
thumb_width 646
thumb_height 484

You would want to fill the values with something like (this is pseudocode):
$smallerDimension = min($raw_width, $raw_height);
$thumb_x = (int) ($raw_width / 2) - ($smallerDimension / 2);
$thumb y = 0;
$thumb_width = $smallerDimension;
$thumb_height = $smallerDimension;

And then your changes will be editable with the edit tool. I think.

 
Terje-
Terje-'s picture

Joined: 2004-01-20
Posts: 90
Posted: Sat, 2005-09-10 01:06

Yeah, very bad things.

so far I've spent 6 hours trying to figure out how to "get back" my thumbnails in G2, still no solution.

Anyone got *any* advice what's causing the problem, and how one can solve it when upgrading to G2?

 
TroublePup

Joined: 2005-11-14
Posts: 1
Posted: Mon, 2005-11-14 05:22

I'm new to gallery, but I LOVE the software. It's amazing how many features a community like this provides.

I am totally new to PHP.. so I don't know exactly how to just look at the code and see what it does. What I'm hoping to do with my project is this:

I am building a Flash site and I want to integrate photos into some of the animation, but I want the photo's to be dynamic. I had intended on using the gallery to be a photo content management system on the backend for the site owner, that would allow him to upload the pictures and edit the information. My Flash site would take the pictures and include them in the animations. My problem/question is this. I can find in my directory where the program is storing the original photo. Is it creating and storing a thumbnail as well? I would love for my flash application to access the photo, the thumbnail, and any comment information that has been created. As it is now, the flash can access the main photo, but I don't want it to have to use the processor to resize the image on the fly.

Any suggestions... the less PHP I have to use the better. I want to learn, but I would rather find a shorter/easier way in the meantime.