Persistent photo size when browsing

netbymatt

Joined: 2008-03-01
Posts: 6
Posted: Sat, 2008-07-05 17:51

I provide two sizes for all of my photos, one with a max of 800px and one with a max of 1024px which work nicely with 1024x768 and 1280x1024 monitors, respectively. The default is the 800px photo, however when I'm looking at my gallery on a larger monitor I like to use the larger size, so I select it from the drop down menu. The problem is, when I click the next image link, the link points to the default size 800px photo. Is there a way for the size selection to carry through on the next and previous links, or better yet, through a browsing session (probably by using a cookie)?

Example page to start from:
http://photos.netbymatt.com/2008/fireworks74/IMG_2815.JPG.html

Thanks in advance!

Gallery version = 2.2.4 core 1.2.0.6
PHP version = 5.2.5 cgi-fcgi
Webserver = Apache
Database = mysql 5.0.45-log, lock.system=flock
Toolkits = Exif, ImageMagick
Acceleration = full/1209600, full/1209600
Operating system = Linux linhost294.prod.mesa1.secureserver.net 2.4.21-53.ELsmp #1 SMP Wed Nov 14 03:54:12 EST 2007 i686
Default theme = netbymatt
gettext = enabled
Locale = en_US
Browser = Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9) Gecko/2008052906 Firefox/3.0
Rows in GalleryAccessMap table = 9
Rows in GalleryAccessSubscriberMap table = 2594
Rows in GalleryUser table = 2
Rows in GalleryItem table = 2593
Rows in GalleryAlbumItem table = 111
Rows in GalleryCacheMap table = 371

Login or register to post comments
alecmyers

Joined: 2006-08-01
Posts: 1840
Posted: Sat, 2008-07-05 18:22

There's no way at present unless you want to hack the core code and add the feature yourself.

Login or register to post comments
vanowm

Joined: 2008-06-27
Posts: 6
Posted: Sun, 2008-07-06 22:56

I've solved this by storing imageViewsIndex value in the session.

In modules\core\classes\GalleryTheme.class find:$imageViewsIndex = is_numeric($imageViewsIndex) ? abs((int)$imageViewsIndex) : null;
Below that line insert this:

	$session =& $gallery->getSession();
	if ($imageViewsIndex !== null)
	{
		$session->put("imageViewsIndex", $imageViewsIndex);
	}
	else
	{
		$imageViewsIndex = $session->get("imageViewsIndex");
		$imageViewsIndex = is_numeric($imageViewsIndex) ? abs((int)$imageViewsIndex) : null;
	}
Login or register to post comments
alecmyers

Joined: 2006-08-01
Posts: 1840
Posted: Sun, 2008-07-06 23:04

cool! I'm sure that will be very useful for a lot of people. Suggestion: have a chat with the Gallery developers on #gallery at irc.freenode.net and see if you can work it up into an accepted code revision.

Login or register to post comments
vanowm

Joined: 2008-06-27
Posts: 6
Posted: Sun, 2008-07-06 23:19

The thing is, since each album or image can have its own resizes, the stored imageViewsIndex value may provide unexpected results. because imageViewsIndex=2 in one album might show images 800x600 in other the same index might have 1600x1200 size.
Until developers integrate different (or alternate) method in requesting resizes (i.e. instead of indexes use max size number) this method will never be very practical unless your gallery has the same resizes everywhere.

Login or register to post comments
alecmyers

Joined: 2006-08-01
Posts: 1840
Posted: Sun, 2008-07-06 23:26

I had a conversation with someone in the team about storing the size of the last "selected" image in the session (i.e. the size of the image you were shown last time you deliberately picked a size) then defaulting to the resize that's no bigger than that, whenever a new image is shown (not sure if that's a clear description or not.) I think the idea got shelved for some not-very-good reason.

It wouldn't be hard to to elaborate on your modification to do something a little more general, either like I was thinking or some other way that makes sense, I don't think.

Login or register to post comments
netbymatt

Joined: 2008-03-01
Posts: 6
Posted: Sun, 2008-07-06 23:47

Thanks for the code, works great. I had considered implementing that myself, but I had the same concern about the imageViewsIndex being used instead of a physical size. I'm ok with that, however, because I have my defaults set and I stick to them, so I'll always have the same size photos in the same imageViewsIndex.

Login or register to post comments
vanowm

Joined: 2008-06-27
Posts: 6
Posted: Sun, 2008-07-27 00:21

Alright, here is a first attempt to use selected maximum image dimension instead of imageViewsIndex:
If you added my previous modifications, remove them.

In modules\core\classes\GalleryTheme.class find:
$imageViewsIndex = is_numeric($imageViewsIndex) ? abs((int)$imageViewsIndex) : null;
Below that line insert this:

	$imageViewsIndexTmp = false;
	if ($imageViewsIndex !== null)
	{
		$imageViewsIndexTmp = true;
	}

Find next:
if (isset($sourceImageViewIndex)) {
Above (note above, not below) that line insert:

		$session =& $gallery->getSession();
		if ($imageViewsIndexTmp)
		{
			$session->put("imageViewsMax", max($imageViews[$imageViewsIndex]['width'], $imageViews[$imageViewsIndex]['height']));
		}
		else
		{
			
			$max = intval($session->get("imageViewsMax"));
			if ($max)
			{
				$imageViewsIndexTmp = 0;
				foreach($imageViews as $key => $val)
				{
					if ($max >= $imageViews[$key]['width'] && $max >= $imageViews[$key]['height'])
					{
						$imageViewsIndexTmp = $key;
					}
					else
					{
						break;
					}
				}
				$imageViewsIndex = $imageViewsIndexTmp;
			}
			
		}

At the moment all my images are with the same resized dimensions, so I couldn't fully test it, but so far it looked as good as my first modification ;)

A quick example on how it should work:
You have an image with resized dimensions of 640x480 and 1024x768. You selected 1024x768. The number 1024 (maximum dimension) will be stored in the session. Then when you visit another image which has resized dimension of 480x640, 600x800 and 1200x1600 it should select 600x800 because its the largest dimension from the list that doesn't exceed number 1024.

P.S.
Just tested and it seems works fine as long as no template caching (acceleration) is activated (admin -> performance)

Login or register to post comments
alecmyers

Joined: 2006-08-01
Posts: 1840
Posted: Mon, 2008-07-07 09:29

Looks great!
First comment from me: obviously you can format the code any way you like, but if you want to join in the way the rest of Gallery is laid out, you might like a read through of this page:
http://codex.gallery2.org/Gallery2:Coding_Standards
It makes it easier for everyone else to follow too.

Also I know that for performance reasons a session entry in the DB isn't created for every user until it's needed (you open a shopping cart, you log in) so I don't know whether you'd consider this setting sufficient to require the creation of a session entry where one doesn't exist (for every guest user etc) but my guess is probably not. So maybe follow up how the session code works and see how that could be tied in?

Login or register to post comments
vanowm

Joined: 2008-06-27
Posts: 6
Posted: Mon, 2008-07-07 14:30

I have no clue how the gallery works, especially sessions...

As of code format, thank you for the link.
I should've break that long line, but regarding curly brackets - I don't like how developers using them, they put the open bracket at the end of the line so it doesn't aligned on same column with the closing one, IMHO its hard to find if you accidentally missed one and...doesn't look nice :)

P.S.
My editor use tabs equal of two spaces, that's why it might look weird in other editors, and that's why G2 code weird in my editor :)

Login or register to post comments
alecmyers

Joined: 2006-08-01
Posts: 1840
Posted: Mon, 2008-07-07 14:48

I guess one of the things about "playing nicely" in the Gallery project is to bite the bullet and set your editor to 8 spaces per tab, learn to enjoy putting the { at the end of the line, and be prepared to learn about things like sessions!

Login or register to post comments