Customized Gallery: Square Thumbnails

richbl

Joined: 2004-05-30
Posts: 43
Posted: Mon, 2004-06-14 17:39

Hello all,

This Gallery community has been great to learn from, so I'd like to give back some of what I've learned.

As I'm new to PHP, I thought I'd use Gallery as a vehicle for teaching myself some PHP. My goal was to integrate Gallery pages into my already-existing personal website (written in xhtml strict/javascript/css2).

With very little ramp-up, I've managed to do just that: create some webpages that are functionally equivalent and just about indistinguishable from my previous work.

Here's an example of a webpage created with a customized Gallery:

http://businesslearninginc.com/familyphotos/gallery/view_album.php?set_albumName=northwest_festivals

Some highlights:

--Square thumbnails that use alpha-channel blending
--Extraction of IPTC header data for image captions and reference
--Added IPTC sort order (based on REFNUMBER, but can be any IPTC header value)
--Personalized look and feel (removed login, custom headers, footers, navbars, etc.)

Overall, I'm very satisfied with the results (everything is still a work in progress). The only real downside that I've come across is that Gallery is table-based, while I prefer working in divs, which allow for dynamically-resizing web content. A minor downside that--with some additional persistence--could be overcome.

If anyone's interested in how some of this work was accomplished, reply here and I'll offer some direction.

thanks again,

rich

 
jseal

Joined: 2004-05-21
Posts: 28
Posted: Mon, 2004-06-14 20:45

I love the square thumbnails! Nice work! I was wondering what exactly alpha channel blending is? I am interested in it.

Also, I'll see if I can find it but fairly recently someone posted a modified Gallery that used pure CSS and no tables. It's in this Customization thread somewhere.

Nice Work!

 
webseth

Joined: 2003-06-13
Posts: 33
Posted: Mon, 2004-06-14 22:34

how do you make it do the square thumbnails without editing each one? ive been wanting that forever, my old arles gallery maker did that.

- Seth

 
richbl

Joined: 2004-05-30
Posts: 43
Posted: Mon, 2004-06-14 23:19
jseal wrote:
I love the square thumbnails! Nice work! I was wondering what exactly alpha channel blending is? I am interested in it.

Also, I'll see if I can find it but fairly recently someone posted a modified Gallery that used pure CSS and no tables. It's in this Customization thread somewhere.

Nice Work!

Thanks for the comments on the thumbnails.

The alpha filter governs the opacity or "see-through-ness" of a CSS object. For my website, I enabled this through CSS as follows:

img.img-thumbnail-overlay
{
-moz-opacity: 0.5;
filter: alpha(opacity = 50);
}

Note that there are two properties that get set depending on platform. The first handles Mozilla-based browsers (I prefer Mozilla Firefox, nee Firebird nee Phoenix). The second is IE-specific and is actually a MS visual filter (for additional details on using this particular filter, see http://msdn.microsoft.com/workshop/author/filter/reference/filters/alpha.asp). It would be interesting to know if other platform-based browers such as Konqueror correctly interpret such alpha filters, but that's a separate issue (it should gracefully degrade such that no effect will be exercised, so I'm not too concerned).

What's really great about Gallery is that, when customized correctly, such effects as these are easily integrated with no difficulties or side-effects.

rich

 
richbl

Joined: 2004-05-30
Posts: 43
Posted: Tue, 2004-06-15 01:26
webseth wrote:
how do you make it do the square thumbnails without editing each one? ive been wanting that forever, my old arles gallery maker did that.

- Seth

Thumbnails get created whenever you add a photo to Gallery (this should be pretty obvious). Thumbnail size is governed by the "Thumbnail size" value in the album properties dialog. The default behavior of Gallery is to resize the image using this value while maintaining the aspect ratio of the original image.

However, what I was looking for was slightly different. I wanted to resize the image as well, but then crop it into a square shape. Additionally, the width (or height, which are now identical) of the cropped shape should be equal to the value of the "Thumbnail size" value in the properties dialog.

This last paragraph is interesting in that it takes into account one initial short-coming that I originally ran into, which was what can happen if an image--with both a width and height greater than "Thumbnail size"--gets resized such that the aspect ratio of the original image forces either values below the desired thumbnail size value. I hope that makes sense. Play around with resizing tall/thin and short/fat images in your favorite image editor, and you'll get the idea.

Time to look at some code. I'm running Gallery 1.4.2, so your code may look different (though the logic is obviously still good).

Managing image resizing is handled in util.php, function resize_image(), which does some sizing logic (the stuff I'm interested in), and then turns around and calls function compress_image(), which is a wrapper for external calls to NetPBM or ImageMagick. I could've recreated a separate resizing function so as to guarantee no side effects, but since I only care about image resizing for thumbnails, I went ahead and altered this primary resize routine.

In util.php, function resize_image(), where the following logic exists:

$target=min($target, max($regs[0],$regs[1]));

I've replaced with:

$aspect_ratio = (min($regs[0],$regs[1])) / (max($regs[0],$regs[1]));
  $target = round($target / $aspect_ratio);

This handles the minimum thumbnail size issue. Basically, I look for smallest value aspect ratio and use that as my target size value. Since an aspect ratio is just a dimension multiplier, it's a very useful way to make sure that I meet the "Thumbnail size" requirement.

So at this point, I'm guaranteed that any dimension of an image (height or width) will not fall below the "Thumbnail size" value.

As for the logic that calls resize_image() and subsequently crops the image (handled by cut_image()), this exists in class AlbumItem, held in AlbumItem.php, function makethumbnail().

Note the code marked with ####. These indicate logic changes:

function makeThumbnail($dir, $thumb_size, $pathToThumb="")
    {
    global $gallery;
    $name = $this->image->name;
    $tag = $this->image->type;
    
    // ####
    $this->image->setThumbRectangle(0, 0, $gallery->album->fields["thumb_size"], $gallery->album->fields["thumb_size"]);    

    if (isMovie($tag))
      {
      /* Use a preset thumbnail */
      fs_copy($gallery->app->movieThumbnail, "$dir/$name.thumb.jpg");
      $this->thumbnail = new Image;
      $this->thumbnail->setFile($dir, "$name.thumb", "jpg");
    
      list($w, $h) = getDimensions("$dir/$name.thumb.jpg");
      $this->thumbnail->setDimensions($w, $h);
      }
    else
      {
      /* Make thumbnail (first crop it spec) */
      if ($pathToThumb)
        {
        $ret = copy ($pathToThumb,"$dir/$name.thumb.$tag");
        }
      else if ($this->image->thumb_width > 0)
        {
        // ####
        $ret = resize_image("$dir/$name.$tag", "$dir/$name.thumb2.$tag", $thumb_size);
        
        $ret = cut_image("$dir/$name.thumb2.$tag", 
                 "$dir/$name.thumb.$tag", 
                 $this->image->thumb_x, 
                 $this->image->thumb_y,
                 $this->image->thumb_width, 
                 $this->image->thumb_height);
                 
        // ####
        if (fs_file_exists("$dir/$name.thumb2.$tag"))
          {
          fs_unlink("$dir/$name.thumb2.$tag");
          }                                 
                 
        if ($ret)
          {
          $ret = resize_image("$dir/$name.thumb.$tag", "$dir/$name.thumb.$tag", $thumb_size);
          }
        }
      else
        {
        $ret = resize_image("$dir/$name.$tag", "$dir/$name.thumb.$tag", $thumb_size);
        }

      if ($ret)
        { 
        $this->thumbnail = new Image;
        $this->thumbnail->setFile($dir, "$name.thumb", $tag);
  
        list($w, $h) = getDimensions("$dir/$name.thumb.$tag");
        $this->thumbnail->setDimensions($w, $h);

        /* if this is the highlight, remake it */
        if ($this->highlight)
          {
          $this->setHighlight($dir, 1);
          }
        }
      else
        {
        return _("Unable to make thumbnail") ." ($ret)";
        }
      }

    return 0;
    }

The first edit,

// ####
  $this->image->setThumbRectangle(0, 0, $gallery->album->fields["thumb_size"], $gallery->album->fields["thumb_size"]);

correctly sets the dimension fields for the thumbnail. I'm not sure why this function is not called at all, since the subsequent logic appears to query the values in these fields.

The second edit,

// ####
  $ret = resize_image("$dir/$name.$tag", "$dir/$name.thumb2.$tag", $thumb_size);

makes a call into resize_image() and creates a temporary file that is the thumbnail, correctly resized, but not yet cropped. Note that a temporary file is required, as either resize_image() or cut_image() (which one escapes me now) will not permit identical source and destination file handles passed into it.

After the call to cut_image() to crop the thumbnail, clean-up is required to remove the temporary thumbnail file:

// ####
  if (fs_file_exists("$dir/$name.thumb2.$tag"))
    {
    fs_unlink("$dir/$name.thumb2.$tag");
    }

The rest of the function logic is left untouched.

Hope this helps.

rich

 
Shadow_Wolf
Shadow_Wolf's picture

Joined: 2004-04-03
Posts: 181
Posted: Tue, 2004-07-06 18:37

I really love the square thumbnails. That is great. I've followed the instructions and tried to apply it but instead I get something different. It looks like it resized them, however it didn't make them squares, I have rectangles though. Did I do something wrong?

Example is here:
http://www.protoculturex.com/index.php?pid=9

Edit: I forgot direct linking doesn't work well with an IFrame. Here is the correct link:
http://www.protoculturex.com/artgallery/view_album.php?set_albumName=album32&s=

 
Luxus

Joined: 2004-07-07
Posts: 30
Posted: Wed, 2004-07-07 04:54

hmm this hack dont work with the cvs version from today :(

another problem is that if orginal image is really large, the thumbs looks bad because this hack only grab a small square from the middle

perhaps someone can update and enhance this hack?

now i will try if it is work with the current release :D

edit:

ahh cool i see shadow have the same problems
with a older version...

 
richbl

Joined: 2004-05-30
Posts: 43
Posted: Wed, 2004-07-07 12:09
Shadow_Wolf wrote:
I really love the square thumbnails. That is great. I've followed the instructions and tried to apply it but instead I get something different. It looks like it resized them, however it didn't make them squares, I have rectangles though. Did I do something wrong?

Example is here:
http://www.protoculturex.com/index.php?pid=9

Edit: I forgot direct linking doesn't work well with an IFrame. Here is the correct link:
http://www.protoculturex.com/artgallery/view_album.php?set_albumName=album32&s=

Shadow Wolf,

I'm currently out of town until 7/15, so I won't be able to give you a hand troubleshooting until then.

rich

 
richbl

Joined: 2004-05-30
Posts: 43
Posted: Wed, 2004-07-07 12:23
Luxus wrote:
hmm this hack dont work with the cvs version from today :(

another problem is that if orginal image is really large, the thumbs looks bad because this hack only grab a small square from the middle

perhaps someone can update and enhance this hack?

now i will try if it is work with the current release :D

edit:

ahh cool i see shadow have the same problems
with a older version...

Luxus,

The hack was only created for version 1.4.2, as noted in my original post. While the logic will still apply to subsequent releases of Gallery, you (or I) would need to rewrite the code against the new sources accordingly.

As I migrate my sites to the current Gallery release, I'll also be updating the sources. Until then, read through and understand the logic, and you'll be in good shape.

To ammend your other comment, the square thumbnail uses the upper-left (0, 0) corner of an image, and not the middle as you indicate.

rich

 
Gaile

Joined: 2002-07-20
Posts: 1301
Posted: Wed, 2004-07-07 18:24

Nice work - this is quite a difference from the standard gallery look!

My only problem is with the mouseover fade, it seems to be a little off in Mozilla. And the popups - sometimes I'm ending up with several popups staying open, and they load much slower than in IE (I looked at your site in IE as well to see what exactly it should be doing, and compared to what it was doing in Mozilla). Other than that, I think it's very well done.

I noticed your use of Terragen too, btw - I forgot about that program!

At any rate, your entire site is very nicely done, and very unique looking. Congratulations! :)

Gaile

 
Luxus

Joined: 2004-07-07
Posts: 30
Posted: Wed, 2004-07-07 18:39

ok i will play around with the source...
the util.php can be the same if i understand it right...
so only the AlbumItem.php need a facelift..

 
Luxus

Joined: 2004-07-07
Posts: 30
Posted: Wed, 2004-07-07 20:43

outdated

 
Shadow_Wolf
Shadow_Wolf's picture

Joined: 2004-04-03
Posts: 181
Posted: Thu, 2004-07-08 16:37

Since the problem I had was that it created Rectangles could it be because of this line:
$this->image->setThumbRectangle(0, 0, $gallery->album->fields["thumb_size"], $gallery->album->fields["thumb_size"]);

Is there a setThumbSquare or some function/command like that instead of a setThumbRectanble?

 
FerN

Joined: 2004-06-30
Posts: 7
Posted: Mon, 2004-07-12 18:54

Hi, Rich,

The square thumbs are working ok (I have 1.4.2). A little problem, though. As Luxus indicated above there is some objections when using big pictures. I usually upload 1024x768 images. And the thumbnail only shows a small 120 (my thumbnail size value) pixels square from the top left of the original photo. So they are not at all useful, as the image is not recognizable.
In your albums, it doesn't seem to work this way. I mean, the thumbnails show a perfect fit to the minimun dimension (width or height of the original photo).
Any suggestion?

Thanks a lot. I was really looking for square thumbnails.

FerN.

 
Shadow_Wolf
Shadow_Wolf's picture

Joined: 2004-04-03
Posts: 181
Posted: Mon, 2004-07-12 19:10

If I understand what he said earlier, it pulls it from the upper left hand corner because the x/y coordinates for it is 0,0:

Quote:
// ####
$this->image->setThumbRectangle(0, 0, $gallery->album->fields["thumb_size"], $gallery->album->fields["thumb_size"]);

If you change the 0,0 to something else like 100, 100 or something else. Have to mess with it a bit that will change where it crops the image from, probably want cordinates from near the center.

---

Anyone have any luck getting this to work with 1.4.3?

 
FerN

Joined: 2004-06-30
Posts: 7
Posted: Mon, 2004-07-12 22:01

Hi, Shadow, Rich,
I am a bit further understanding the hack. The problem I mentionned above was logical. I had not updated this in the cut image function:

Quote:
$ret = cut_image("$dir/$name.thumb2.$tag",
"$dir/$name.thumb.$tag",

So I was just getting the square rectangle from the original image into the thumbnail, thus a tiny portion of the original image, without any resizing.

But now, I have changed the code as indicated by Rich, and it doesn't work. The thumb2 file is created with the right resizing (I have tested without deleting the thumb2 file, and seeing the image directly). But the thumb file does not work. This means that the cut function is failing. As I don't know php, could you please tell me where the error could be, or give me any hint!!

Thanks.
FerN.

 
richbl

Joined: 2004-05-30
Posts: 43
Posted: Fri, 2004-07-16 22:44
richbl wrote:
Luxus wrote:
hmm this hack dont work with the cvs version from today :(

another problem is that if orginal image is really large, the thumbs looks bad because this hack only grab a small square from the middle

perhaps someone can update and enhance this hack?

now i will try if it is work with the current release :D

edit:

ahh cool i see shadow have the same problems
with a older version...

Luxus,

The hack was only created for version 1.4.2, as noted in my original post. While the logic will still apply to subsequent releases of Gallery, you (or I) would need to rewrite the code against the new sources accordingly.

As I migrate my sites to the current Gallery release, I'll also be updating the sources. Until then, read through and understand the logic, and you'll be in good shape.

To ammend your other comment, the square thumbnail uses the upper-left (0, 0) corner of an image, and not the middle as you indicate.

rich

Hello all,

As I'm back from my respite with some good news, as I can confirm that the hack as described in this thread does work for Gallery v1.4.3-pl2, as evidenced here:

http://beta.businesslearninginc.com/gallery/northwest_festivals

As several folks have had some issues with the square thumbs, I'll help each in order as posted.

One quick observation (without looking at anyone's code) is that I run this hack on a box that uses NetPBM and not ImageMagick, so it's possible (again, an untested theory at this moment) that the problems some folks are having is related to the platform graphics toolset. When I get back into my sources, I should be able to better judge this observation.

thanks,

rich

 
richbl

Joined: 2004-05-30
Posts: 43
Posted: Fri, 2004-07-16 22:52
PixelPoet wrote:
Nice work - this is quite a difference from the standard gallery look!

My only problem is with the mouseover fade, it seems to be a little off in Mozilla. And the popups - sometimes I'm ending up with several popups staying open, and they load much slower than in IE (I looked at your site in IE as well to see what exactly it should be doing, and compared to what it was doing in Mozilla). Other than that, I think it's very well done.

I noticed your use of Terragen too, btw - I forgot about that program!

At any rate, your entire site is very nicely done, and very unique looking. Congratulations! :)

Gaile

Thanks for the kudos.

With what version of Mozilla are you viewing the site? I've seen the problem that you describe, but only under older browser releases.

Also, I'm very aware of the pop-up situation... so much so that I'm slowing doing away with them, and replacing them with what I've done in Gallery (the original impetus to move over to Gallery in fact ;)): pop-ups these days are pretty much verboten.

thanks again,

rich

 
richbl

Joined: 2004-05-30
Posts: 43
Posted: Fri, 2004-07-16 23:10
Shadow_Wolf wrote:
If I understand what he said earlier, it pulls it from the upper left hand corner because the x/y coordinates for it is 0,0:

Quote:
// ####
$this->image->setThumbRectangle(0, 0, $gallery->album->fields["thumb_size"], $gallery->album->fields["thumb_size"]);

If you change the 0,0 to something else like 100, 100 or something else. Have to mess with it a bit that will change where it crops the image from, probably want cordinates from near the center.

---

Anyone have any luck getting this to work with 1.4.3?

Hi Shadow Wolf,

I can confirm that the hack will work in Gallery v1.4.3-pl2, as evidenced here:

http://beta.businesslearninginc.com/gallery/northwest_festivals

Since I'm still trying to understand why you might be having problems, can you please answer the following questions for me:

A) Can you display square thumbs (regardless of what part of the image it grabs, just whether you have it working at all)?
B) If not working, are you using NetPBM or ImageMagick?

Functionally, the code should handle any image size passed to it, as it ultimately resizes it based on thumb_size.

thanks much,

rich

 
richbl

Joined: 2004-05-30
Posts: 43
Posted: Fri, 2004-07-16 23:22
FerN wrote:
Hi, Rich,

The square thumbs are working ok (I have 1.4.2). A little problem, though. As Luxus indicated above there is some objections when using big pictures. I usually upload 1024x768 images. And the thumbnail only shows a small 120 (my thumbnail size value) pixels square from the top left of the original photo. So they are not at all useful, as the image is not recognizable.
In your albums, it doesn't seem to work this way. I mean, the thumbnails show a perfect fit to the minimun dimension (width or height of the original photo).
Any suggestion?

Thanks a lot. I was really looking for square thumbnails.

FerN.

Hi FerN,

Thanks for the feedback.

You are correct in your observation: the hack for square thumbs should handle any image size, as it simply makes a call to resize_image() (which in turn, calls compress_image()).

However, what I'm starting to suspect is whether calls into the two platform graphics toolkits might have an influence on outcome. My system uses NetPBM, so it's possible (though just a theory at this point) that ImageMagick handles resizing/cropping differently.

Can you please answer for me whether you're running Gallery on a system that uses NetPBM or ImageMagick?

thanks much,

rich

 
Shadow_Wolf
Shadow_Wolf's picture

Joined: 2004-04-03
Posts: 181
Posted: Mon, 2004-07-19 15:27

FerN: If you look in your config.php for $gallery->app->graphics =, you'll see either ImageMagick or NetPBM.

richbl: When I had the hack installed I was only able to get rectangle thumbnails, it would not create square thumbnails at all. I tried deleting all thumbnails and recreating them, still same thing. The only way I could get square thumbnails was to manually resize thumbnail.

I am using ImageMagick not NetPBM. I have also placed util.php and AlbumItem.php into a zip file so you can take a look and make sure I followed your instructions correctly. I've attached it here.

I redid the changes again following the instructions just to make sure I didn't make any mistakes. I'm still getting the same thing. However I am having another issue. I didn't want to mess with any of my artists galleries so I made a test gallery and when I try to upload I get the following error:

Processing status... 

- Adding arsea.gif 
   Resizing/compressing original image 
   No resizing required 
   No resizing required 
Error: Unable to make thumbnail (0)! 
Need help? Look in the Gallery FAQ 

Removing the AlbumItem.php and replacing it with my backup that had no changes, I was able to upload fine. So whatever changes are made in AlbumItem.php seem to be what effects my ability to upload images. I know its not the changes in util.php because I still have the one with the changes uploaded and its not giving me any issues.

 
Luxus

Joined: 2004-07-07
Posts: 30
Posted: Mon, 2004-07-19 17:19

hmmm i try it again... with a fresh gallery installation
and it don't work again
i create a fresh album and add 2 pictures
http://test.blogout.de/gallery/album11
and i try recreate thumbs from an exist album.
no squared thumbs
i before i start i set to netpbm for image manipulation
here are the party i modified:

util.php

// ### square hack start
// Old line
//      $target=min($target, max($regs[0],$regs[1]));
//
$aspect_ratio = (min($regs[0],$regs[1])) / (max($regs[0],$regs[1]));
  $target = round($target / $aspect_ratio);
//
// ### square hack end

classes/AlbumItem.php

 function makeThumbnail($dir, $thumb_size, &$album, $pathToThumb="")
        {
// ### square hack start
    $this->image->setThumbRectangle(0, 0, $gallery->album->fields["thumb_size"], $gallery->album->fields["thumb_size"]);
// ### square hack end

                global $gallery;
                $name = $this->image->name;
                $tag = $this->image->type;

                if ($this->isMovie()) {
                        /* Use a preset thumbnail */
                        fs_copy($gallery->app->movieThumbnail, "$dir/$name.thumb.jpg");
                        $this->thumbnail = new Image;
                        $this->thumbnail->setFile($dir, "$name.thumb", "jpg");

                        list($w, $h) = getDimensions("$dir/$name.thumb.jpg");
                        $this->thumbnail->setDimensions($w, $h);
                } else {
                        /* Make thumbnail (first crop it spec) */
                        if ($pathToThumb) {
                                $ret = copy($pathToThumb,"$dir/$name.thumb.$tag");
                        }
                        else if ($this->image->thumb_width > 0) {

// ### Square hack start
        $ret = resize_image("$dir/$name.$tag", "$dir/$name.thumb2.$tag", $thumb_size);
                                // ### Old line $ret = cut_image("$dir/$name.$tag",
                                                $ret = cut_image("$dir/$name.thumb2.$tag",
// ### square hack end
                                                                 "$dir/$name.thumb.$tag",
                                                                 $this->image->thumb_x,
                                                                 $this->image->thumb_y,
                                                                 $this->image->thumb_width,
                                                                 $this->image->thumb_height);

// ### square hack start
        if (fs_file_exists("$dir/$name.thumb2.$tag"))
          {
          fs_unlink("$dir/$name.thumb2.$tag");
          }
// ### square hack end
                                if ($ret) {
                                        $ret = resize_image("$dir/$name.thumb.$tag",
                                                                                "$dir/$name.thumb.$tag", $thumb_size);
                                }
                        } else {
                                $ret = resize_image("$dir/$name.$tag", "$dir/$name.thumb.$tag",
                                             $thumb_size);
                        }

                        if ($ret) {
                        if ($ret) {
                                $this->thumbnail = new Image;
                                $this->thumbnail->setFile($dir, "$name.thumb", $tag);

                                list($w, $h) = getDimensions("$dir/$name.thumb.$tag");
                                $this->thumbnail->setDimensions($w, $h);

                                /* if this is the highlight, remake it */
                                if ($this->highlight) {
                                        $this->setHighlight($dir, 1, $album);
                                }
                        } else {
                                return _("Unable to make thumbnail") ." ($ret)";
                        }
                }

                return 0;
        }  

am i doing something wrong?

perhaps u can just post your files for Gallery v1.4.4 RC 2

edit oh i see u are not using the latest release in your new gallery :(

 
coops
coops's picture

Joined: 2002-10-31
Posts: 40
Posted: Tue, 2004-07-20 12:15

I've got it to make new uploads have square thumbnails - but the result is that the album highlight on the parent page is a low-res of the top corner of the highlight photo.

Is there a way for the highlight photo to be different from the album thumbnail?

--Coops

examples at:

http://testing.coopersphotos.co.uk/gallery/ [and
http://beta.businesslearninginc.com/gallery/]

 
Luxus

Joined: 2004-07-07
Posts: 30
Posted: Tue, 2004-07-20 17:13

hmpf.. as i see it is easy to add the hack in the older version...
rich pleaaaase update your very nice hack!

 
richbl

Joined: 2004-05-30
Posts: 43
Posted: Wed, 2004-07-21 20:22

Hello all,

For completeness, I've reposted the sources for square thumbnails below. These are for the current release version of Gallery, v1.4.3-pl2 (as of this writing, v1.4.4 is still a release candidate).

An example of square thumbnails in use can be seen here (Gallery v1.4.2):

http://businesslearninginc.com/familyphotos/gallery/view_album.php?set_albumName=northwest_festivals

And here (Gallery v1.4.3-pl2):

http://beta.businesslearninginc.com/gallery/northwest_festivals

There are two files that require changes: util.php and AlbumItem.php.

In util.php, function resize_image() is changed to provide the logic for resizing an image based on the "Thumbnail size" parameter available through the properties dialog. Note also that in the transition from Gallery v.1.4.2 to the current release (v1.4.3-pl2), resize_image() return values are altered. This point will be important when revisiting changes in AlbumItem.php (below).

Note the code marked with ####. These indicate logic changes:

function resize_image($src, $dest, $target=0, $target_fs=0, $keepProfiles=0) {
	/*
	 *  Valid return codes:
	 *  0:  File was not resized, no processing to be done
	 *  1:  File resized, process normally
	 *  2:  Existing resized file should be removed
	 */
	global $gallery;				
  
	if (!strcmp($src,$dest)) {
		$useTemp = true;
		$out = "$dest.tmp";
	}
	else {
		$out = $dest;
		$useTemp = false;
	}

	$regs = getimagesize($src);
	if ($regs[2] !== 2 && $regs[2] !== 3) {
		$target_fs = 0; // can't compress other images
	}
	if ($target === 'off') {
	    $target = 0;
	}
		
	/* Check for images smaller then target size, don't blow them up. */
	$regs = getDimensions($src, $regs);
	if ((empty($target) || ($regs[0] <= $target && $regs[1] <= $target))
			&& (empty($target_fs) || ((int) fs_filesize($src) >> 10) <= $target_fs)) {
		processingMsg("&amp;&amp;&amp;". _("No resizing required"));
		if ($useTemp == false && !strstr($dest, ".sized.")) {
			fs_copy($src, $dest);
			return 1;
		}
		elseif (fs_file_exists($dest) && strstr($dest, ".sized.")) {
			return 2;
		}
		return 0;
	}
  
// #### 
// $target=min($target, max($regs[0],$regs[1]));

  $aspect_ratio = (min($regs[0],$regs[1])) / (max($regs[0],$regs[1]));
  $target = round($target / $aspect_ratio);

	if ($target_fs == 0) {
		compress_image($src, $out, $target, $gallery->app->jpegImageQuality, $keepProfiles);
	} else {
		$filesize = (int) fs_filesize($src) >> 10;
		$max_quality=$gallery->app->jpegImageQuality;
		$min_quality=5;
		$max_filesize=$filesize;
		$min_filesize=0;
		if (!isset($quality)) {
			$quality=$gallery->album->fields['last_quality'];
		}
		processingMsg("&amp;&amp;&amp;". sprintf(_("target file size %d kbytes"), 
					$target_fs)."<br>");

		do {
			compress_image($src, $out, $target, $quality, $keepProfiles);
			$prev_quality=$quality;
			printf(_("-> file size %d kbytes"), round($filesize));
			processingMsg("&amp;&amp;&amp;" . sprintf(_("trying quality %d%%"), 
						$quality));
			clearstatcache();
			$filesize= (int) fs_filesize($out) >> 10;
			if ($filesize < $target_fs) {
				$min_quality=$quality;
				$min_filesize=$filesize;
			} else if ($filesize > $target_fs){
				$max_quality=$quality;
				$max_filesize=$filesize;
			} else if ($filesize == $target_fs){
				$min_quality=$quality;
				$max_quality=$quality;
				$min_filesize=$filesize;
				$max_filesize=$filesize;
			}
			$quality=($max_quality + $min_quality)/2;
			$quality=round($quality);
			if ($quality==$prev_quality) {
				if ($filesize==$max_filesize) {
					$quality--;
				} else {
					$quality++;
				}
			}
		} while ($max_quality-$min_quality > 2 && 
				abs(($filesize-$target_fs)/$target_fs) > .02 );

		$gallery->album->fields['last_quality']=$prev_quality;
		printf(_("-> file size %d kbytes"), round($filesize));
		processingMsg(_("Done."));
	}
	if (fs_file_exists("$out") && fs_filesize("$out") > 0) {
		if ($useTemp) {
			fs_copy($out, $dest);
			fs_unlink($out);
		}
		return 1;
	} else {
		return 0;
	}
}

In class AlbumItem.php, function makeThumbnail() is also changed. When an image is passed into makeThumbnail(), the final desired thumbnail dimensions are first set, the image is resized, and then cropped into a square.

Note the code marked with ####. These indicate logic changes:

function makeThumbnail($dir, $thumb_size, &$album, $pathToThumb="")
	  {
		global $gallery;
		$name = $this->image->name;
		$tag = $this->image->type;

    // ####
    $this->image->setThumbRectangle(0, 0, $gallery->album->fields["thumb_size"],$gallery->album->fields["thumb_size"]);    
    
		if (isMovie($tag))
      {
			/* Use a preset thumbnail */
			fs_copy($gallery->app->movieThumbnail, "$dir/$name.thumb.jpg");
			$this->thumbnail = new Image;
			$this->thumbnail->setFile($dir, "$name.thumb", "jpg");

			list($w, $h) = getDimensions("$dir/$name.thumb.jpg");
			$this->thumbnail->setDimensions($w, $h);
		  }
    else
      {
			/* Make thumbnail (first crop it spec) */
			if ($pathToThumb)
        {
				$ret = copy ($pathToThumb,"$dir/$name.thumb.$tag");
			  }
      else if ($this->image->thumb_width > 0)
			  {        
        // ####
        $ret = resize_image("$dir/$name.$tag", "$dir/$name.thumb2.$tag", $thumb_size);

        $ret = cut_image("$dir/$name.thumb2.$tag",
                 "$dir/$name.thumb.$tag",
                 $this->image->thumb_x,
                 $this->image->thumb_y,
                 $this->image->thumb_width,
                 $this->image->thumb_height);
                 
        // ####
        if (fs_file_exists("$dir/$name.thumb2.$tag"))
          {
          fs_unlink("$dir/$name.thumb2.$tag");
          }     
                                      
// ####        
//				if ($ret)
//          {
//					$ret = resize_image("$dir/$name.thumb.$tag","$dir/$name.thumb.$tag", $thumb_size);
//				  }
			  }
      else
        {
				$ret = resize_image("$dir/$name.$tag", "$dir/$name.thumb.$tag", $thumb_size);
			  }

			if ($ret)
        { 
				$this->thumbnail = new Image;
				$this->thumbnail->setFile($dir, "$name.thumb", $tag);
	
				list($w, $h) = getDimensions("$dir/$name.thumb.$tag");
				$this->thumbnail->setDimensions($w, $h);

				/* if this is the highlight, remake it */
				if ($this->highlight)
          {
					$this->setHighlight($dir, 1, $album);
				  }
			  }
      else
        {
				return _("Unable to make thumbnail") ." ($ret)";
			  }
		  }
		return 0;
	  }

As mentioned earlier, with this current release of Gallery, function resize_image() was changed so it now returns different values (i.e., 0, 1, 2). As a result, makeThumbnail() would incorrectly fail though the thumbnail was correctly resized and cropped. To alleviate the problem with this new functionality, the second call in makeThumbnail() to resize_image() was removed (it was superfluous).

One side-affect of which I'm aware (and has since been mentioned in this thread) is that the images used in Gallery index pages are affected by this hack. This is correct, and though unintentional, is not of particular concern to me, as I don't explicitly use Gallery index pages. The solution to resolving this would be to create some logic that toggled the functionality of square thumbnails such that Gallery functions calling into makeThumbnail() can either choose square thumbnails, or the original uncropped thumbnails instead. While not a significant undertaking, it does add to the complexity of the code that would need to be written.

As always, if you have questions, please ask and I will do my best to help clarify.

thanks,

rich

 
richbl

Joined: 2004-05-30
Posts: 43
Posted: Wed, 2004-07-21 20:39
Shadow_Wolf wrote:
FerN: If you look in your config.php for $gallery->app->graphics =, you'll see either ImageMagick or NetPBM.

richbl: When I had the hack installed I was only able to get rectangle thumbnails, it would not create square thumbnails at all. I tried deleting all thumbnails and recreating them, still same thing. The only way I could get square thumbnails was to manually resize thumbnail.

I am using ImageMagick not NetPBM. I have also placed util.php and AlbumItem.php into a zip file so you can take a look and make sure I followed your instructions correctly. I've attached it here.

I redid the changes again following the instructions just to make sure I didn't make any mistakes. I'm still getting the same thing. However I am having another issue. I didn't want to mess with any of my artists galleries so I made a test gallery and when I try to upload I get the following error:

Processing status... 

- Adding arsea.gif 
   Resizing/compressing original image 
   No resizing required 
   No resizing required 
Error: Unable to make thumbnail (0)! 
Need help? Look in the Gallery FAQ 

Removing the AlbumItem.php and replacing it with my backup that had no changes, I was able to upload fine. So whatever changes are made in AlbumItem.php seem to be what effects my ability to upload images. I know its not the changes in util.php because I still have the one with the changes uploaded and its not giving me any issues.

Hi Shadow_Wolf,

Looking at the sources that you provided, I can see at least one problem. Please recheck the original source code (I've also just posted sources for the more recent Gallery release, v1.4.3-pl2).

In AlbumItem.php (your AlbumItembackup.php), function makeThumbnail(), line 518 is:

// #### 
$ret = resize_image("$dir/$name.$tag", "$dir/$name.thumb2.$tag", $thumb_size); 

$ret = cut_image("$dir/$name.$tag", 
  "$dir/$name.thumb.$tag", 
  $this->image->thumb_x, 
  $this->image->thumb_y,
  $this->image->thumb_width, 
  $this->image->thumb_height);

Note that function cut_image() should take the temporary thumbnail thumb2, as follows:

// ####
$ret = resize_image("$dir/$name.$tag", "$dir/$name.thumb2.$tag", $thumb_size);

$ret = cut_image("$dir/$name.thumb2.$tag",
  "$dir/$name.thumb.$tag",
  $this->image->thumb_x,
  $this->image->thumb_y,
  $this->image->thumb_width,
  $this->image->thumb_height);

That should resolve your issue.

rich

 
Shadow_Wolf
Shadow_Wolf's picture

Joined: 2004-04-03
Posts: 181
Posted: Thu, 2004-07-22 03:25

That didn't work but I did forget one thing. I didn't comment these out.

// ####        
//            if ($ret) 
//          { 
//               $ret = resize_image("$dir/$name.thumb.$tag","$dir/$name.thumb.$tag", $thumb_size); 
//              }

That completely fixed it which does bring up the issue of the main gallery page also being squares and something else. Almost all my artists love the square images, there are a couple though that prefer the old method. Would there be a way to create it so the user can choose what method they want? By doing so could it be worked in to solve the issue with the main gallery page as well?

 
richbl

Joined: 2004-05-30
Posts: 43
Posted: Sat, 2004-07-24 02:54
Shadow_Wolf wrote:
That didn't work but I did forget one thing. I didn't comment these out.

// ####        
//            if ($ret) 
//          { 
//               $ret = resize_image("$dir/$name.thumb.$tag","$dir/$name.thumb.$tag", $thumb_size); 
//              }

That completely fixed it which does bring up the issue of the main gallery page also being squares and something else. Almost all my artists love the square images, there are a couple though that prefer the old method. Would there be a way to create it so the user can choose what method they want? By doing so could it be worked in to solve the issue with the main gallery page as well?

Glad to hear you have things working.

Your idea for creating a toggle between square and rectangular thumbs is a good one. It's certainly possible, but would require some work with creating a checkbox (or some like user interface element) on the preferences page or perhaps even in config.php. I'd have to defer that work to someone better suited to this task, as I'm still very new to the Gallery framework. As the scope of this feature continues to mature, it might be an ideal time to make a feature request to the Gallery team.

Regarding the side-effect with the main gallery page, I do have a solution that I will post shortly. In this, I provide (albeit programmatically) a way to display either square or rectangular highlight thumbnails on the Gallery album index page.

Regards.

rich

 
richbl

Joined: 2004-05-30
Posts: 43
Posted: Sat, 2004-07-24 03:12

I've made one addition to the square thumbnail hack which alleviates the side-effect previously discussed on this thread. Specifically, on Gallery album index pages, the code changes to generate square thumbnails would alter the highlighted image on the index page.

Since I don't make explicit use of these index pages, I originally had little interest in the side-effect produced. However, for those who use album index pages (and I'd guess most do), I've made the appropriate code changes.

I'm currently using Gallery v1.4.3-pl2, but the logic changes suggested here should work for prior versions, as well as the upcoming v.1.4.4 release.

The code change involves function setHighlight(), found in AlbumItem.php. Note the code marked with ####. These indicate logic changes:

  function setHighlight($dir, $bool, &$album, $name = null, $tag = null, $srcdir = null, $srcitem = null)
    {
    global $gallery;

    $this->highlight = $bool;

    /*
     * if it is now the highlight make sure it has a highlight
     * thumb otherwise get rid of it's thumb (ouch!).
     */

    if ($this->highlight)
      {
      if (!isset($name))
        {
        $name = $this->image->name;
        $tag = $this->image->type;
        $srcdir = $dir;
        $srcitem = $this;
        if ($this->isAlbumName)
          {
          $name = $this->isAlbumName;
          $nestedAlbum = new Album();
          $nestedAlbum->load($name);
          list($srcalbum, $srcitem) = $nestedAlbum->getHighlightedItem();
          if ($srcalbum !== null && $srcitem !== null)
            {
            $srcdir = $srcalbum->getAlbumDir();
            $tag = $srcitem->image->type;
            }
          else
            {
            if (is_object($this->highlightImage))
              {
              $this->highlightImage->simpleDelete($dir);
              $this->highlightImage = null;
              }
            return ;
            }
          }
        }
      $size = $album->getHighlightSize();

      if ($srcitem->image->thumb_width > 0)
        {
// ####        
        $ret = resize_image("$srcdir/".$srcitem->image->name.".$tag",
          "$dir/$name.tmp.$tag", $size);

        if ($ret)
          {
          $ret = cut_image("$dir/$name.tmp.$tag",
            "$dir/$name.highlight.$tag", $srcitem->image->thumb_x, $srcitem->image
            ->thumb_y, $size, $size);
          }
          
        fs_unlink("$dir/$name.tmp.$tag");
                  
// ####          
/*        
        // Crop it first
        $ret = cut_image("$srcdir/".$srcitem->image->name.".$tag",
          "$dir/$name.tmp.$tag", $srcitem->image->thumb_x, $srcitem->image
          ->thumb_y, $srcitem->image->thumb_width, $srcitem->image
          ->thumb_height);
          
        // Then resize it down
        if ($ret)
          {
          $ret = resize_image("$dir/$name.tmp.$tag",
            "$dir/$name.highlight.$tag", $size);
          }
          
        fs_unlink("$dir/$name.tmp.$tag");
*/
          
        }
      elseif ($this->isMovie())
        {
        $tag = substr(strrchr($gallery->app->movieThumbnail, '.'), 1);
        $ret = resize_image($gallery->app->movieThumbnail,
          "$dir/$name.highlight.$tag", $size);
        }
      else
        {
        $ret = resize_image("$srcdir/".$srcitem->image->name.".$tag",
          "$dir/$name.highlight.$tag", $size);
        }

      if ($ret)
        {
        list($w, $h) = getDimensions("$dir/$name.highlight.$tag");

        $high = new Image;
        $high->setFile($dir, "$name.highlight", "$tag");
        $high->setDimensions($w, $h);
        $this->highlightImage = $high;

        /* Check if we need to cascade highlight up to parent album */
        $parentAlbum = &$album->getParentAlbum();        
        if (isset($parentAlbum) && !strcmp($parentAlbum->version, $gallery
          ->album_version))
          {
          $highlightIndex = $parentAlbum->getHighlight();
          if ($highlightIndex == $parentAlbum->getAlbumIndex($album
            ->fields['name']))
            {
            $item = &$parentAlbum->getPhoto($highlightIndex);
            $item->setHighlight($parentAlbum->getAlbumDir(), 1, $parentAlbum,
              $album->fields['name'], $tag, $srcdir, $srcitem);
            $parentAlbum->save(array(), 0);
            }
          }          
        }
      }
    else
      {
      if (is_object($this->highlightImage))
        {
        $this->highlightImage->simpleDelete($dir);
        $this->highlightImage = null;
        }
      }
    }

This change mirrors the program logic found in my customized function makeThumbnail() (also found in AlbumItem.php): the image in question is first resized, then cropped to produce the resulting square thumbnail image.

A slight variation which might be of interest to some would be to resize the highlight image, but not crop it square. The solution entails removing the cut_image() function (responsible for image cropping), and making a change to the output arguement in the preceeding resize_image() routine. Note the code fragment below:

...
      if ($srcitem->image->thumb_width > 0)
        {
// ####        
        $ret = resize_image("$srcdir/".$srcitem->image->name.".$tag",
          "$dir/$name.highlight.$tag", $size);

// ####          
/*        
        // Crop it first
        $ret = cut_image("$srcdir/".$srcitem->image->name.".$tag",
          "$dir/$name.tmp.$tag", $srcitem->image->thumb_x, $srcitem->image
          ->thumb_y, $srcitem->image->thumb_width, $srcitem->image
          ->thumb_height);
          
        // Then resize it down
        if ($ret)
          {
          $ret = resize_image("$dir/$name.tmp.$tag",
            "$dir/$name.highlight.$tag", $size);
          }

        fs_unlink("$dir/$name.tmp.$tag");          
*/
        }
...

Enjoy.

rich

 
Shadow_Wolf
Shadow_Wolf's picture

Joined: 2004-04-03
Posts: 181
Posted: Sat, 2004-07-24 03:36

Absolutely wonderful and amazing, works like a charm as seen here.

I only have a few questions.

1) How does the resizing of the original index page album picture differ from how it does it now? The reason I ask the last album here you can see its a crisp image. The image here isn't as crisp (this is the modified coded image).

2) What is the code that originally did the highlight image resize? I was wondering if it is then possibly use a if Highlight image then it uses that method to create a album thumb or something.

3) Where are the x/y coords to where it will tell it to start the resize, Is that here "$this->image->setThumbRectangle(0, 0," ? The reason I'm asking is because with a large 1024 image, I've tried setting to settings like 4000, 6000 and it still doesn't resize from closer to the center of the image, it seems to still do it in the upper left hand corner.

4) This is for anyone... Anyone good with php and more familar with Gallery know how to add a checkbox option in Album Properties? It would be nice if someone knew how to add a "If item is checked then it will use new square resize method or else use original resize method". That would give people who have multiple users choose which they prefer for their albums.

Once again, great modification, I love it. :)

 
strikker

Joined: 2004-08-05
Posts: 23
Posted: Fri, 2004-08-06 19:37

Hey all, Well I tried the latest update hear to try and get the square hack to work in my gallery. I get an error:
Parse error: parse error, unexpected '\"' in /home/dibsdetr/public_html/tiseo/gallery/classes/AlbumItem.php on line 584

The version is 1.4.4-RC2 does anyone know how to get this to work with this version? Below is my code.

util.php:

function resize_image($src, $dest, $target=0, $target_fs=0, $keepProfiles=0) {
	/*
	 *  Valid return codes:
	 *  0:  File was not resized, no processing to be done
	 *  1:  File resized, process normally
	 *  2:  Existing resized file should be removed
	 */
	global $gallery;				

	if (!strcmp($src,$dest)) {
		$useTemp = true;
		$out = "$dest.tmp";
	}
	else {
		$out = $dest;
		$useTemp = false;
	}

	$regs = getimagesize($src);
	if ($regs[2] !== 2 && $regs[2] !== 3) {
		$target_fs = 0; // can't compress other images
	}
	if ($target === 'off') {
	    $target = 0;
	}
		
	/* Check for images smaller then target size, don't blow them up. */
	$regs = getDimensions($src, $regs);
	if ((empty($target) || ($regs[0] <= $target && $regs[1] <= $target))
			&& (empty($target_fs) || ((int) fs_filesize($src) >> 10) <= $target_fs)) {
		processingMsg("&amp;&amp;&amp;". _("No resizing required"));

		/* If the file is already smaller than the target filesize, don't
		 * create a new sized image.  return 2 indicates that the current .sized.
		 * needs to be removed */
		if ($useTemp == false && !strstr($dest, ".sized.")) {
			fs_copy($src, $dest);
			return 1;
		}
		elseif (fs_file_exists($dest) && strstr($dest, ".sized.")) {
			return 2;
		}
		return 0;
	}

// ####
//$target=min($target, max($regs[0],$regs[1]));

  $aspect_ratio = (min($regs[0],$regs[1])) / (max($regs[0],$regs[1])); 
  $target = round($target / $aspect_ratio);

	if ($target_fs == 0) {
		compress_image($src, $out, $target, $gallery->app->jpegImageQuality, $keepProfiles);
	} else {
		$filesize = (int) fs_filesize($src) >> 10;
		$max_quality=$gallery->app->jpegImageQuality;
		$min_quality=5;
		$max_filesize=$filesize;
		$min_filesize=0;
		if (!isset($quality)) {
			$quality=$gallery->album->fields['last_quality'];
		}
		processingMsg("&amp;&amp;&amp;". sprintf(_("target file size %d kbytes"), 
					$target_fs)."\n");

		do {
			compress_image($src, $out, $target, $quality, $keepProfiles);
			$prev_quality=$quality;
			printf(_("-> file size %d kbytes"), round($filesize));
			processingMsg("&amp;&amp;&amp;" . sprintf(_("trying quality %d%%"), 
						$quality));
			clearstatcache();
			$filesize= (int) fs_filesize($out) >> 10;
			if ($filesize < $target_fs) {
				$min_quality=$quality;
				$min_filesize=$filesize;
			} else if ($filesize > $target_fs){
				$max_quality=$quality;
				$max_filesize=$filesize;
			} else if ($filesize == $target_fs){
				$min_quality=$quality;
				$max_quality=$quality;
				$min_filesize=$filesize;
				$max_filesize=$filesize;
			}
			$quality=($max_quality + $min_quality)/2;
			$quality=round($quality);
			if ($quality==$prev_quality) {
				if ($filesize==$max_filesize) {
					$quality--;
				} else {
					$quality++;
				}
			}
		} while ($max_quality-$min_quality > 2 && 
				abs(($filesize-$target_fs)/$target_fs) > .02 );

		$gallery->album->fields['last_quality']=$prev_quality;
		printf(_("-> file size %d kbytes"), round($filesize));
		processingMsg(_("Done."));
	}
	if (fs_file_exists("$out") && fs_filesize("$out") > 0) {
		if ($useTemp) {
			fs_copy($out, $dest);
			fs_unlink($out);
		}
		return 1;
	} else {
		return 0;
	}
}

The code of AlbumItem.php

function makeThumbnail($dir, $thumb_size, &$album, $pathToThumb="")
	{
	global $gallery;
	$name = $this->image->name;
	$tag = $this->image->type;

// ####
$this->image->setThumbRectangle(0, 0, $gallery->album->fields
["thumb_size"],$gallery->album->fields["thumb_size"]);

	if (isMovie($tag))
	 {
	/* Use a preset thumbnail */
	fs_copy($gallery->app->movieThumbnail, "$dir/$name.thumb.jpg");
	$this->thumbnail = new Image;
	$this->thumbnail->setFile($dir, "$name.thumb", "jpg");

	list($w, $h) = getDimensions("$dir/$name.thumb.jpg");
	$this->thumbnail->setDimensions($w, $h);
	} 
	else
	{
	/* Make thumbnail (first crop it spec) */
	if ($pathToThumb) {
	$ret = copy($pathToThumb,"$dir/$name.thumb.$tag");
	} 
	else if ($this->image->thumb_width > 0)
	 {
	// ####
	$ret = resize_image("$dir/$name.$tag", "$dir/$name.thumb2.$tag",
	$thumb_size);
					
	$ret = cut_image("$dir/$name.thumb2.$tag", 
			 "$dir/$name.thumb.$tag", 
			 $this->image->thumb_x, 
			 $this->image->thumb_y,
			 $this->image->thumb_width, 
			 $this->image->thumb_height);
				
			// ####
			if (fs_file_exists("$dir/$name.thumb2.$tag")) 
          			{ 
          			fs_unlink("$dir/$name.thumb2.$tag"); 
          			}  
// ####								
//			if ($ret) {
//			$ret = resize_image("$dir/$name.thumb.$tag", "$dir/
$name.thumb.$tag", $thumb_size);
//			}
			} else {
			$ret = resize_image("$dir/$name.$tag", "$dir/$name.thumb.$tag",
			$thumb_size);
			}

		if ($ret) { 
			$this->thumbnail = new Image;
			$this->thumbnail->setFile($dir, "$name.thumb", $tag);
	
			list($w, $h) = getDimensions("$dir/$name.thumb.$tag");
			$this->thumbnail->setDimensions($w, $h);

			/* if this is the highlight, remake it */
			if ($this->highlight) {
			$this->setHighlight($dir, 1, $album);
				}
			} else {
				return _("Unable to make thumbnail") ." ($ret)";
			}
		}

		return 0;
	}

So I hope someone can help me get this working! Thank you for any effort!

 
richbl

Joined: 2004-05-30
Posts: 43
Posted: Fri, 2004-08-06 20:09

Strikker,

A parse error indicates that there is a typographical error in your code, and not a logical error. A cursory look through your code would suggest that you may have a wrapped uncommented line that is the cause of the parse error:

// ####								
//			if ($ret) {
//			$ret = resize_image("$dir/$name.thumb.$tag", "$dir/
$name.thumb.$tag", $thumb_size);
//			}

From what you posted, I cannot determine if the wrap was a result of your post, or if it was wrapped in code, in which case it would most certainly be the cause of the parse error.

I am not familiar with the sources in RC2 for Gallery v1.4.4 (release candidates, by definition, are unstable), but I will be posting updated sources of my code running in the released version of Gallery v1.4.4 shortly.

Best of luck.

rich

 
strikker

Joined: 2004-08-05
Posts: 23
Posted: Fri, 2004-08-06 20:58

Ok your allsome that did get it to work!
One problem and one question though.

Now what happens to my images is they expand beyond my max res.

Thumbnail for album gets created as a square and is at 0,0 and the thumbnail inside of that is ok but now my picutres are to big and is falling outside of my layout.

Does this hack control the image creation/scale size?

If it created the images to the size that it does when I leave those 2 files alone things would be perfect.

Thanks again

 
richbl

Joined: 2004-05-30
Posts: 43
Posted: Fri, 2004-08-06 21:11

Hello all,

With the final release of Gallery v1.4.4, I've updated the sources for square thumbnails below.

An example of square thumbnails in use can be seen here:

http://businesslearninginc.com/familyphotos/gallery/view_album.php?set_albumName=northwest_festivals

There are two php files that are affected by the change to square thumbnails: AlbumItem.php (in the classes folder), and util.php (in the Gallery root). Within AlbumItem.php, function makeThumbnail() receives the logic changes. Optionally, for those Gallery users who make use of Gallery index pages, function setHighlight() is also changed. In util.php, function resize_image() is altered.

Sources for each of the three functions are listed below. Note the #### edits, which indicate changes in logic:

In file AlbumItem.php, function makeThumbnail():

  
function makeThumbnail($dir, $thumb_size, &$album, $pathToThumb="")
  {
    global $gallery;
    $name = $this->image->name;
    $tag = $this->image->type;

// ####
    $this->image->setThumbRectangle(0, 0, $gallery->album->fields["thumb_size"],$gallery->album->fields["thumb_size"]);    
   
    if ($this->isMovie()) {
      /* Use a preset thumbnail */
      fs_copy($gallery->app->movieThumbnail, "$dir/$name.thumb.jpg");
      $this->thumbnail = new Image;
      $this->thumbnail->setFile($dir, "$name.thumb", "jpg");

      list($w, $h) = getDimensions("$dir/$name.thumb.jpg");
      $this->thumbnail->setDimensions($w, $h);
    } else {
      /* Make thumbnail (first crop it spec) */
      if ($pathToThumb) {
        $ret = copy($pathToThumb,"$dir/$name.thumb.$tag");
      } 
      else if ($this->image->thumb_width > 0) {

// ####>
        $ret = resize_image("$dir/$name.$tag", "$dir/$name.thumb2.$tag", $thumb_size);

        $ret = cut_image("$dir/$name.thumb2.$tag",
                 "$dir/$name.thumb.$tag",
                 $this->image->thumb_x,
                 $this->image->thumb_y,
                 $this->image->thumb_width,
                 $this->image->thumb_height);
                 
        if (fs_file_exists("$dir/$name.thumb2.$tag"))
          {
          fs_unlink("$dir/$name.thumb2.$tag");
          }                                           
// <####
      
      } else {
        $ret = resize_image("$dir/$name.$tag", "$dir/$name.thumb.$tag",
               $thumb_size);
      }

      if ($ret) { 
        $this->thumbnail = new Image;
        $this->thumbnail->setFile($dir, "$name.thumb", $tag);
  
        list($w, $h) = getDimensions("$dir/$name.thumb.$tag");
        $this->thumbnail->setDimensions($w, $h);

        /* if this is the highlight, remake it */
        if ($this->highlight) {
          $this->setHighlight($dir, 1, $album);
        }
      } else {
        return _("Unable to make thumbnail") ." ($ret)";
      }
    }

    return 0;
  }

In file AlbumItem.php, function setHighlight():

function setHighlight($dir, $bool, &$album,
      $name=null, $tag=null, $srcdir=null, $srcitem=null) {
    global $gallery;
    
    $this->highlight = $bool;
    
    /*
     * if it is now the highlight make sure it has a highlight
                 * thumb otherwise get rid of it's thumb (ouch!).
     */

    if ($this->highlight) {
      if (!isset($name)) {
        $name = $this->image->name;
        $tag = $this->image->type;
        $srcdir = $dir;
        $srcitem = $this;
        if ($this->isAlbum()) {
          $name = $this->getAlbumName();
          $nestedAlbum = new Album();
          $nestedAlbum->load($name);
          list ($srcalbum, $srcitem) = $nestedAlbum->getHighlightedItem();
          if ($srcalbum !== null && $srcitem !== null) {
            $srcdir = $srcalbum->getAlbumDir();
            $tag = $srcitem->image->type;
          }
          else {
            if (is_object($this->highlightImage)) {
              $this->highlightImage->simpleDelete($dir);
              $this->highlightImage = null;
            }
            return;
          }
        }
      }
      $size = $album->getHighlightSize();
      
      if ($srcitem->image->thumb_width > 0  && !$this->isMovie()) {
      
// ####>
        $ret = resize_image("$srcdir/".$srcitem->image->name.".$tag",
          "$dir/$name.tmp.$tag", $size);

        if ($ret)
          {
          $ret = cut_image("$dir/$name.tmp.$tag",
            "$dir/$name.highlight.$tag", $srcitem->image->thumb_x, $srcitem->image
            ->thumb_y, $size, $size);
          }
          
        fs_unlink("$dir/$name.tmp.$tag");
// <####

        }      
      elseif ($this->isMovie()) {
        if (fs_file_exists($gallery->app->movieThumbnail)) {
          $tag = substr(strrchr($gallery->app->movieThumbnail, '.'), 1);
          $ret = resize_image($gallery->app->movieThumbnail, "$dir/$name.highlight.$tag", $size);
        }
        else {
          $ret = 0;
        }
      } else {
        $ret = resize_image("$srcdir/".$srcitem->image->name.".$tag",
                "$dir/$name.highlight.$tag",
                $size);
      }

      if ($ret) {
        list($w, $h) = getDimensions("$dir/$name.highlight.$tag");
        $high = new Image;
        $high->setFile($dir, "$name.highlight", "$tag");
        $high->setDimensions($w, $h);
        $this->highlightImage = $high;

        /* Check if we need to cascade highlight up to parent album */
        $parentAlbum =& $album->getParentAlbum();
        if (isset($parentAlbum) && !strcmp($parentAlbum->version, $gallery->album_version)) {
          $highlightIndex = $parentAlbum->getHighlight();
          if ($highlightIndex == $parentAlbum->getAlbumIndex($album->fields['name'])) {
            $item = &$parentAlbum->getPhoto($highlightIndex);
            $item->setHighlight($parentAlbum->getAlbumDir(), 1, $parentAlbum, $album->fields['name'], $tag, $srcdir, $srcitem);
            $parentAlbum->save(array(),0);
          }
        }
      }
    } else {
      if (is_object($this->highlightImage)) {
        $this->highlightImage->simpleDelete($dir);
        $this->highlightImage = null;
      }
    }
  }

In file util.php, function resize_image():

function resize_image($src, $dest, $target=0, $target_fs=0, $keepProfiles=0) {
  /*
   *  Valid return codes:
   *  0:  File was not resized, no processing to be done
   *  1:  File resized, process normally
   *  2:  Existing resized file should be removed
   */
  global $gallery;        

  if (!strcmp($src,$dest)) {
    $useTemp = true;
    $out = "$dest.tmp";
  }
  else {
    $out = $dest;
    $useTemp = false;
  }

  $regs = getimagesize($src);
  if ($regs[2] !== 2 && $regs[2] !== 3) {
    $target_fs = 0; // can't compress other images
  }
  if ($target === 'off') {
      $target = 0;
  }
    
  /* Check for images smaller then target size, don't blow them up. */
  $regs = getDimensions($src, $regs);
  if ((empty($target) || ($regs[0] <= $target && $regs[1] <= $target))
      && (empty($target_fs) || ((int) fs_filesize($src) >> 10) <= $target_fs)) {
    processingMsg("&amp;&amp;&amp;". _("No resizing required"));

    /* If the file is already smaller than the target filesize, don't
     * create a new sized image.  return 2 indicates that the current .sized.
     * needs to be removed */
    if ($useTemp == false && !strstr($dest, ".sized.")) {
      fs_copy($src, $dest);
      return 1;
    }
    elseif (fs_file_exists($dest) && strstr($dest, ".sized.")) {
      return 2;
    }
    return 0;
  }
        
// ####> 
  $aspect_ratio = (min($regs[0],$regs[1])) / (max($regs[0],$regs[1]));
  $target = round($target / $aspect_ratio);
// <####
  
  $target=min($target, max($regs[0],$regs[1]));

  if ($target_fs == 0) {
    compress_image($src, $out, $target, $gallery->app->jpegImageQuality, $keepProfiles);
  } else {
    $filesize = (int) fs_filesize($src) >> 10;
    $max_quality=$gallery->app->jpegImageQuality;
    $min_quality=5;
    $max_filesize=$filesize;
    $min_filesize=0;
    if (!isset($quality)) {
      $quality=$gallery->album->fields['last_quality'];
    }
    processingMsg("&amp;&amp;&amp;". sprintf(_("target file size %d kbytes"), 
          $target_fs)."\n");

    do {
      compress_image($src, $out, $target, $quality, $keepProfiles);
      $prev_quality=$quality;
      printf(_("-> file size %d kbytes"), round($filesize));
      processingMsg("&amp;&amp;&amp;" . sprintf(_("trying quality %d%%"), 
            $quality));
      clearstatcache();
      $filesize= (int) fs_filesize($out) >> 10;
      if ($filesize < $target_fs) {
        $min_quality=$quality;
        $min_filesize=$filesize;
      } else if ($filesize > $target_fs){
        $max_quality=$quality;
        $max_filesize=$filesize;
      } else if ($filesize == $target_fs){
        $min_quality=$quality;
        $max_quality=$quality;
        $min_filesize=$filesize;
        $max_filesize=$filesize;
      }
      $quality=($max_quality + $min_quality)/2;
      $quality=round($quality);
      if ($quality==$prev_quality) {
        if ($filesize==$max_filesize) {
          $quality--;
        } else {
          $quality++;
        }
      }
    } while ($max_quality-$min_quality > 2 && 
        abs(($filesize-$target_fs)/$target_fs) > .02 );

    $gallery->album->fields['last_quality']=$prev_quality;
    printf(_("-> file size %d kbytes"), round($filesize));
    processingMsg(_("Done."));
  }
  if (fs_file_exists("$out") && fs_filesize("$out") > 0) {
    if ($useTemp) {
      fs_copy($out, $dest);
      fs_unlink($out);
    }
    return 1;
  } else {
    return 0;
  }
}

Cheers.

rich

 
richbl

Joined: 2004-05-30
Posts: 43
Posted: Fri, 2004-08-06 21:43
Shadow_Wolf wrote:
Absolutely wonderful and amazing, works like a charm as seen here.

I only have a few questions.

1) How does the resizing of the original index page album picture differ from how it does it now? The reason I ask the last album here you can see its a crisp image. The image here isn't as crisp (this is the modified coded image).

2) What is the code that originally did the highlight image resize? I was wondering if it is then possibly use a if Highlight image then it uses that method to create a album thumb or something.

3) Where are the x/y coords to where it will tell it to start the resize, Is that here "$this->image->setThumbRectangle(0, 0," ? The reason I'm asking is because with a large 1024 image, I've tried setting to settings like 4000, 6000 and it still doesn't resize from closer to the center of the image, it seems to still do it in the upper left hand corner.

4) This is for anyone... Anyone good with php and more familar with Gallery know how to add a checkbox option in Album Properties? It would be nice if someone knew how to add a "If item is checked then it will use new square resize method or else use original resize method". That would give people who have multiple users choose which they prefer for their albums.

Once again, great modification, I love it. :)

Shadow_Wolf,

In response to your questions:

1) I haven't been able to track this down, but I suspect that somewhere, Gallery is resizing the thumbnail (actually the highlight image) twice. And, if you have your jpg compression set, successive resizes will degrade image quality regardless of whether the image size actually changed (the degrade happens at time of file save). As a quick solution, you might want to try setting jpg compression to minimal/no compression and observe the results.

2) I don't understand the intent of this question. Please rephrase.

3) This origin for the resize will always be 0,0, regardless of size. The reason for this is that the original image always gets resized to the dimensions you specify (image_size) first. THEN, the crop occurs, making the resulting image square. This is by design.

I think what you're asking is whether it's possible to select an artibitrary origin (e.g. 200, 500) within the original image, then crop a square of image_size. This is possible, but a very different solution with very different visual results. Offhand, here's what you'd want to do:

    1. Pass user origin into function (e.g. 200, 500).
    2. Check again maximum dimensions of image (error case).
    3. Crop image. Save thumbnail.

Note that in this case, the call into resize_image() would not be required.

Best of luck.

rich[/]

 
strikker

Joined: 2004-08-05
Posts: 23
Posted: Fri, 2004-08-06 23:29

Looks good, your new code works good.

How do I get it to use my max/default size of 400px?

Picture view it is now resizing them to big to fit into my layout? Something I need to change? Code is the way you have it now.

 
strikker

Joined: 2004-08-05
Posts: 23
Posted: Sat, 2004-08-07 02:08

I was also very curious how you apply that alpha effect to your css and where to put it on which file.

 
strikker

Joined: 2004-08-05
Posts: 23
Posted: Mon, 2004-08-09 14:54

Anyone have any idea? I must be missing something!

 
richbl

Joined: 2004-05-30
Posts: 43
Posted: Mon, 2004-08-09 16:53
strikker wrote:
Anyone have any idea? I must be missing something!

Yes, read the fourth post on this thread. It describes how the effect was achieved.

rich

 
strikker

Joined: 2004-08-05
Posts: 23
Posted: Mon, 2004-08-09 18:15

Ok thanks for the Alpha help.

Rich do you know why the images are resizing beyond my max res? Or where I control it? I want them to be 400 in width max.

 
richbl

Joined: 2004-05-30
Posts: 43
Posted: Mon, 2004-08-09 22:04
strikker wrote:
Ok thanks for the Alpha help.

Rich do you know why the images are resizing beyond my max res? Or where I control it? I want them to be 400 in width max.

Strikker,

It's unclear as to what images you're referring to in your post. Are you referring to the thumbnail size, intermediate image size, or the actual image size?

In all cases, thumbnail and image sizes are dictated by entries in the Album Properties property sheet. "Thumbnail size" is used in my code to determine the maximum size of an image thumbnail. As for image sizes, I don't make direct use of this information.

You may want to check your entries in the fields for "Maximum dimensions of intermediate sized images" and "Maximum dimensions of full sized images." These will govern the maximum size of your images.

Best of luck.

rich

 
strikker

Joined: 2004-08-05
Posts: 23
Posted: Tue, 2004-08-10 00:19

Hmmm this is so odd then. I did check it and the properties are still where I want them. I did mean the actual image sizes. When I put the original files back (util,album) my images are fine. Weird.

 
beel

Joined: 2004-08-14
Posts: 1
Posted: Sat, 2004-08-14 10:01
richbl wrote:
Hello all,

This Gallery community has been great to learn from, so I'd like to give back some of what I've learned.

As I'm new to PHP, I thought I'd use Gallery as a vehicle for teaching myself some PHP. My goal was to integrate Gallery pages into my already-existing personal website (written in xhtml strict/javascript/css2).

With very little ramp-up, I've managed to do just that: create some webpages that are functionally equivalent and just about indistinguishable from my previous work.

Here's an example of a webpage created with a customized Gallery:

http://businesslearninginc.com/familyphotos/gallery/view_album.php?set_albumName=northwest_festivals

Some highlights:

--Square thumbnails that use alpha-channel blending
--Extraction of IPTC header data for image captions and reference
--Added IPTC sort order (based on REFNUMBER, but can be any IPTC header value)
--Personalized look and feel (removed login, custom headers, footers, navbars, etc.)

Overall, I'm very satisfied with the results (everything is still a work in progress). The only real downside that I've come across is that Gallery is table-based, while I prefer working in divs, which allow for dynamically-resizing web content. A minor downside that--with some additional persistence--could be overcome.

If anyone's interested in how some of this work was accomplished, reply here and I'll offer some direction.

thanks again,

rich

Rich,

I've been trying to put together an online portfolio for my photos, what I want to accomplish is too simplify the gallery interface, so users simply sees thumbnails and photos only. To my surprise you've done quite well in your website that renders the results that one is expecting.

For the easier part, I've implemented your hacks--works like a charm, but when I tried to "copy" your wonderful thumbnail listing, I was back to where I was again--confused.

Would you mind shed me--or us some light on how you achive such a hack? Identical to the result your site has? I'd appreciate it if you could write some bits of tips on it. TiA.

 
richbl

Joined: 2004-05-30
Posts: 43
Posted: Sat, 2004-08-14 17:31
beel wrote:
richbl wrote:
Hello all,

This Gallery community has been great to learn from, so I'd like to give back some of what I've learned.

As I'm new to PHP, I thought I'd use Gallery as a vehicle for teaching myself some PHP. My goal was to integrate Gallery pages into my already-existing personal website (written in xhtml strict/javascript/css2).

With very little ramp-up, I've managed to do just that: create some webpages that are functionally equivalent and just about indistinguishable from my previous work.

Here's an example of a webpage created with a customized Gallery:

http://businesslearninginc.com/familyphotos/gallery/view_album.php?set_albumName=northwest_festivals

Some highlights:

--Square thumbnails that use alpha-channel blending
--Extraction of IPTC header data for image captions and reference
--Added IPTC sort order (based on REFNUMBER, but can be any IPTC header value)
--Personalized look and feel (removed login, custom headers, footers, navbars, etc.)

Overall, I'm very satisfied with the results (everything is still a work in progress). The only real downside that I've come across is that Gallery is table-based, while I prefer working in divs, which allow for dynamically-resizing web content. A minor downside that--with some additional persistence--could be overcome.

If anyone's interested in how some of this work was accomplished, reply here and I'll offer some direction.

thanks again,

rich

Rich,

I've been trying to put together an online portfolio for my photos, what I want to accomplish is too simplify the gallery interface, so users simply sees thumbnails and photos only. To my surprise you've done quite well in your website that renders the results that one is expecting.

For the easier part, I've implemented your hacks--works like a charm, but when I tried to "copy" your wonderful thumbnail listing, I was back to where I was again--confused.

Would you mind shed me--or us some light on how you achive such a hack? Identical to the result your site has? I'd appreciate it if you could write some bits of tips on it. TiA.

Thanks very much for the accolade.

I'd be happy to help out, but what specifically do you have questions about?

rich

 
richbl

Joined: 2004-05-30
Posts: 43
Posted: Thu, 2004-08-19 20:15

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.

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";
...

In edit_appearance.php:

...
if (isset($save)) {
  if (get_magic_quotes_gpc()) {
    $gallery->album->fields["summary"] = stripslashes($summary);
    $gallery->album->fields["title"] = stripslashes($title);
  } else {
    $gallery->album->fields["summary"] = $summary;
    $gallery->album->fields["title"] = $title;
  }
  $gallery->album->fields["bgcolor"] = $bgcolor;
  $gallery->album->fields["textcolor"] = $textcolor;
  $gallery->album->fields["linkcolor"] = $linkcolor;
  $gallery->album->fields["font"] = $font;
  $gallery->album->fields["bordercolor"] = $bordercolor;
  $gallery->album->fields["border"] = $border;
  $gallery->album->fields["background"] = $background;  
  $gallery->album->fields["thumb_size"] = $thumb_size;

// ####  
  $gallery->album->fields["thumb_shape"] = $thumb_shape;
  
  $gallery->album->fields["resize_size"] = $resize_size;
  $gallery->album->fields["resize_file_size"] = $resize_file_size;
  $gallery->album->fields['max_size'] = $max_size;
...

and

...
<tr>
  <td class="popup"><?php echo _("Thumbnail size") ?></td>
  <td><input type="text" name="thumb_size" value="<?php echo $gallery->album->fields["thumb_size"] ?>"></td>
</tr>
<!-- ####> -->  
<tr>
  <td class="popup"><?php echo _("Display square thumbnails") ?></td>
  <td>
  <select name="thumb_shape"><?php echo selectOptions($gallery->album, "thumb_shape", array("yes" => _("yes"), "no" => _("no"))) ?>
  </select>
  </td>
<tr>
<!-- <#### --> 
...

In util.php, function resize_image():

...
// ####
function resize_image($src, $dest, $target=0, $target_fs=0, $keepProfiles=0, $squareThumb="no")
...

and

...
    if ($useTemp == false && !strstr($dest, ".sized."))
      {
      fs_copy($src, $dest);
      return 1;
      }
    elseif (fs_file_exists($dest) && strstr($dest, ".sized."))
      {
      return 2;
      }
      
    return 0;
    }
        
// ####> 
  if ($squareThumb == "yes")
    {
    $aspect_ratio = (min($regs[0],$regs[1])) / (max($regs[0],$regs[1]));
    $target = round($target / $aspect_ratio);
    }
  else
    {
    $target=min($target, max($regs[0],$regs[1]));
    }
// <####

  if ($target_fs == 0)
    {
    compress_image($src, $out, $target, $gallery->app->jpegImageQuality, $keepProfiles);
    }
...    

In util.php, function createNewAlbum():

...
    $gallery->album->fields['background']      = $parentAlbum->fields['background'];
    $gallery->album->fields["font"]            = $parentAlbum->fields["font"];
    $gallery->album->fields["border"]          = $parentAlbum->fields["border"];
    $gallery->album->fields["bordercolor"]     = $parentAlbum->fields["bordercolor"];
    $gallery->album->fields["thumb_size"]      = $parentAlbum->fields["thumb_size"];
    
// ####                
    $gallery->album->fields["thumb_shape"]      = $parentAlbum->fields["thumb_shape"];
               
    $gallery->album->fields["resize_size"]     = $parentAlbum->fields["resize_size"];
    $gallery->album->fields["resize_file_size"]     = $parentAlbum->fields["resize_file_size"];
    $gallery->album->fields['max_size']        = $parentAlbum->fields['max_size'];
    $gallery->album->fields['max_file_size']   = $parentAlbum->fields['max_file_size'];
    $gallery->album->fields['returnto']        = $parentAlbum->fields['returnto'];
...

In Album.php, function Album():

...
    $this->fields["border"] = $gallery->app->default["border"];
    $this->fields["bordercolor"] = $gallery->app->default["bordercolor"];
    $this->fields["returnto"] = $gallery->app->default["returnto"];
    $this->fields["thumb_size"] = $gallery->app->default["thumb_size"];

// ####    
    $this->fields["thumb_shape"] = $gallery->app->default["thumb_shape"];
    
    $this->fields["resize_size"] = $gallery->app->default["resize_size"];
    $this->fields["resize_file_size"] = $gallery->app->default["resize_file_size"];
    $this->fields['max_size'] = $gallery->app->default['max_size'];
    $this->fields['max_file_size'] = $gallery->app->default['max_file_size'];
    $this->fields["rows"] = $gallery->app->default["rows"];
...

In AlbumItem.php, function setHighlight():

...
      $size = $album->getHighlightSize();
            
      if ($srcitem->image->thumb_width > 0  && !$this->isMovie())
        {
      
// ####>
        $squareThumb = $gallery->album->fields["thumb_shape"];
        
        if ($squareThumb == "yes")
          {          

          $ret = resize_image("$srcdir/".$srcitem->image->name.".$tag", "$dir/$name.tmp.$tag", $size, 0, 0, "yes");
  
          if ($ret)
            {
            $ret = cut_image("$dir/$name.tmp.$tag",
              "$dir/$name.highlight.$tag", $srcitem->image->thumb_x, $srcitem->image->thumb_y, $size, $size);
            }
            
          fs_unlink("$dir/$name.tmp.$tag");
          }
        else
          {
          // Crop it first
          $ret = cut_image("$srcdir/".$srcitem->image->name.".$tag",
            "$dir/$name.tmp.$tag",
            $srcitem->image->thumb_x,
            $srcitem->image->thumb_y,
            $srcitem->image->thumb_width,
            $srcitem->image->thumb_height);
  
          // Then resize it down
          if ($ret)
            {
            $ret = resize_image("$dir/$name.tmp.$tag", 
              "$dir/$name.highlight.$tag",
              $size);
            }
            
          fs_unlink("$dir/$name.tmp.$tag");
          } 
// <####

        }      
      elseif ($this->isMovie())
        {
        
        if (fs_file_exists($gallery->app->movieThumbnail))
...

And in AlbumItem.php, function makeThumbnail():

...
    $name = $this->image->name;
    $tag = $this->image->type;
    
    // ####>
    $squareThumb = $gallery->album->fields["thumb_shape"];
        
    if ($squareThumb == "yes")
      {
      $this->image->setThumbRectangle(0, 0, $gallery->album->fields["thumb_size"],
        $gallery->album->fields["thumb_size"]);
      }
    // <####     

     if ($this->isMovie())
...     

and

...
      else if ($this->image->thumb_width > 0) 
        {

// ####>
        if ($squareThumb == "no")
          {
          $ret = cut_image("$dir/$name.$tag", 
            "$dir/$name.thumb.$tag", 
            $this->image->thumb_x, 
            $this->image->thumb_y,
            $this->image->thumb_width, 
            $this->image->thumb_height);
          if ($ret)
            {
            $ret = resize_image("$dir/$name.thumb.$tag", 
              "$dir/$name.thumb.$tag", $thumb_size);
            }
          }
        else
          {  
          $ret = resize_image("$dir/$name.$tag", "$dir/$name.thumb2.$tag", $thumb_size, 0, 0, $squareThumb);
          $ret = cut_image("$dir/$name.thumb2.$tag",
            "$dir/$name.thumb.$tag",
            $this->image->thumb_x,
            $this->image->thumb_y,
            $this->image->thumb_width,
            $this->image->thumb_height);
                 
          if (fs_file_exists("$dir/$name.thumb2.$tag"))
            {
            fs_unlink("$dir/$name.thumb2.$tag");
            }
          }                                           
// <####
      
        } 
      else
        {
        $ret = resize_image("$dir/$name.$tag", "$dir/$name.thumb.$tag", $thumb_size);
        }
...

enjoy,

rich[/]

 
strikker

Joined: 2004-08-05
Posts: 23
Posted: Sat, 2004-09-04 02:17

Hey there,

I put the alpha hack into my css, but which page and where in the document do I apply it?

Thanks

 
strikker

Joined: 2004-08-05
Posts: 23
Posted: Wed, 2004-09-08 14:41

Any suggestions richbl?

 
richbl

Joined: 2004-05-30
Posts: 43
Posted: Sun, 2004-09-12 04:31
strikker wrote:
Any suggestions richbl?

Strikker,

For use in non-Gallery web pages, you'll need to modify your HTML and/or JavaScript code so that the opacity (alpha-channel) CSS style is toggled on receipt of onmouseover and onmouseout events. A fragment of that JavaScript code is described below:

...
document.write('<div class = "div-thumbnail-container">\n');
document.write('<img class = "img-thumbnail-overlay" src = "' + path_image_info + image_info[count][0] + '_small.jpg"');
document.write('onmouseover = "thumbnail_show(this);" onmouseout = "thumbnail_hide(this);" onclick = "image_show(\'' + path_image_info + '\', ' + count + ', 1);"></img>\n');
document.write('</div>\n');
...

Within the Gallery application, the Image class must be rewritten for the same reason: so that the opacity CSS style is toggled on receipt of onmouseover and onmouseout events. This can be accomplished in several different ways. For my implementation, I've modified function getTag() to take an argument, $isthumb, to first determine if the opacity style should even be considered (function getTag() is called for reasons other than creating thumbnail images), as such:

// ####  
function getTag($dir, $full=0, $size=0, $attrs="",$alttext="", $isthumb=1) {
...

Logic further into function getTag() then returns the appropriate HTML tag string, as described below:

...
  if ($this->resizedName && $size == 0)
    {
    if ($full)
      {
      
      // ####>    
      if ($isthumb)
        return "<img class = \"img-thumbnail-overlay\" onmouseover = \"thumbnail_show(this);\" onmouseout = \"thumbnail_hide(this);\" src=\"$dir/$this->name.$this->type\" " . "width=\"$this->raw_width\" height=\"$this->raw_height\" $attrs alt=\"$alttext\" title=\"$alttext\" />";
      else
        return "<img src=\"$dir/$this->name.$this->type\" " . "width=\"$this->raw_width\" height=\"$this->raw_height\" $attrs alt=\"$alttext\" title=\"$alttext\" />";
      }
    else
      {
      if ($isthumb)
        return "<img class = \"img-thumbnail-overlay\" onmouseover = \"thumbnail_show(this);\" onmouseout = \"thumbnail_hide(this);\" src=\"$dir/$this->resizedName.$this->type\" " . "width=\"$this->width\" height=\"$this->height\" " .	"$attrs alt=\"$alttext\" title=\"$alttext\" />";
      else
        return "<img src=\"$dir/$this->resizedName.$this->type\" " . "width=\"$this->width\" height=\"$this->height\" " .	"$attrs alt=\"$alttext\" title=\"$alttext\" />";
      }
    } 
  else 
    {
    if ($isthumb)
      return "<img class = \"img-thumbnail-overlay\" onmouseover = \"thumbnail_show(this);\" onmouseout = \"thumbnail_hide(this);\" src=\"$dir/$this->name.$this->type\" $size_val $attrs alt=\"$alttext\" title=\"$alttext\" />";
    else        
      return "<img src=\"$dir/$this->name.$this->type\" $size_val $attrs alt=\"$alttext\" title=\"$alttext\" />";
    }
  // <####
...

Note the JavaScript calls thumbnail_show(this) and thumbnail_hide(this). These are small JavaScript routines that alter the CSS classnames of the img elements. These routines are presented below:

...
function thumbnail_show(thumbnail)
  {
  thumbnail.className = "img-thumbnail";
  };
  
function thumbnail_hide(thumbnail)
  {
  thumbnail.className = "img-thumbnail-overlay";
  };
...

This should help you get a better understanding of how to implement CSS elements into your Gallery implementation.

rich

 
strikker

Joined: 2004-08-05
Posts: 23
Posted: Mon, 2004-09-13 11:18

Ok thanks bud, I will see if I can figure it out!

 
vivhost

Joined: 2004-11-14
Posts: 1
Posted: Sun, 2004-11-14 10:56

The square thumbnails feature appears to break the "Edit Thumbnail" functionality inside albums admin. I really wish that would work but haven't been able to track where exactly the custom values are getting lost.

 
tmothy

Joined: 2004-03-06
Posts: 53
Posted: Mon, 2004-11-22 08:18

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"