Some Square Thumbnails Module Problems

mingjuwu

Joined: 2004-12-04
Posts: 10
Posted: Sat, 2004-12-04 14:10

The Square Thumbnails Module has the priority hard coded to 10 in

$ret = GalleryCoreApi::registerToolkitOperation('SquareThumb', $mimeTypes, 'thumbnail',
            array(array('type' => 'int', 'description' => $gallery->i18n('target size'))),
            $gallery->i18n('Create square thumbnail'), '', 10);

I changed it to

    list ($ret, $priority) = GalleryCoreApi::getMaximumManagedToolkitPriority();
    if ($ret->isError()) {
        return array($ret->wrap(__FILE__, __LINE__), null);
    }
    $priority++;

// skip

$ret = GalleryCoreApi::registerToolkitOperation('SquareThumb', $mimeTypes, 'thumbnail',
            array(array('type' => 'int', 'description' => $gallery->i18n('target size'))),
            $gallery->i18n('Create square thumbnail'), '', $priority);

and now the module's priority is manageable in ToolKit Priority menu.
Now we can control weither to use square thumbnails or not from the ToolKit Priority menu. I would like to know if this is the right way to have to options into ToolKit Priority menu.

Another thing that I noticed:
After enabling Thumbnails Module and set the "Recreate thumbnails" in an album, the first refresh of the page will not have the right image width and height ratio. The picture is croped into square but the image showed on the webpage still has the dimension from previous thumbnail. The second refresh of the page will fix it.

Thank you for the great work!

 
mingjuwu

Joined: 2004-12-04
Posts: 10
Posted: Sat, 2004-12-04 14:48

FYI, I am unsing 2004-11-04's dailysnap shot.

Just tried to reinstall the gallery again, this time I activated the Square Tumbnails Module from the installer. In gallery module manager "Square Thumbnails Manager" showed inactived.When I try to active the "Square Thumbnails Manager", gallery returned

EDITED: Sorry, the one that is not activated was not "Square Thumbnails Manager", it was "Thumbnail Manager"

Quote:
Error (ERROR_MISSING_OBJECT) : GalleryGroup

* in modules/core/classes/GalleryStorage/DatabaseStorage.class at line 1628 (gallerystatus::error)
* in modules/core/classes/GalleryStorage/DatabaseStorage.class at line 299 (mysqldatabasestorage::_describeentitymembers)
* in modules/core/classes/GalleryStorage.class at line 113 (mysqldatabasestorage::loadentities)
* in modules/core/classes/helpers/GalleryEntityHelper_simple.class at line 89 (gallerystorage::loadentities)
* in modules/core/classes/GalleryCoreApi.class at line 2035 (galleryentityhelper_simple::loadentitiesbyid)
* in modules/core/classes/helpers/GalleryPermissionHelper_advanced.class at line 93 (gallerycoreapi::loadentitiesbyid)
* in modules/core/classes/helpers/GalleryPermissionHelper_advanced.class at line 74 (gallerypermissionhelper_advanced::_postgroupevent)
* in modules/core/classes/GalleryCoreApi.class at line 537 (gallerypermissionhelper_advanced::addgrouppermission)
* in modules/thumbnail/classes/ThumbnailHelper.class at line 213 (gallerycoreapi::addgrouppermission)
* in modules/thumbnail/module.inc at line 122 (thumbnailhelper::additem)
* in modules/core/AdminModules.inc at line 108 (thumbnailmodule::activate)
* in main.php at line 170 (adminmodulescontroller::handlerequest)
* in main.php at line 47
* in main.php at line 40

Tried to upload some picture, and theire thumb nails are square.

P.S.

I tried to reporduce this several times, if you go to the gallery modules manager right after the installation and try to activate it, it will produce this error. But after several tries ( or maybe several minutes ) it will active fine.

 
mingjuwu

Joined: 2004-12-04
Posts: 10
Posted: Sat, 2004-12-04 15:19

Found some weird behavior after the above code modification.

If the Toolkit Priority is

Quote:
SquareThumb down
ImageMagick up down
Gd up down
NetPBM up

Then the correct thumbnail will not show, instead it shows something look like an broken glass.

If I have Gd or NetPBM take ImageMagick's priority then it seems to work fine.

Can someone give me a hint?

Thank you very much.

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Sat, 2004-12-04 16:49

The thumbnail manager error has been reported many times, but no one has gotten any additional debug output to add to this bug.. sounds like you have some coding ability, so maybe you can help here?

Why do you want to add square thumbnaills to the toolkit priority view? You can turn it on/off by activating/deactivating the module in site admin / modules.

 
mingjuwu

Joined: 2004-12-04
Posts: 10
Posted: Sat, 2004-12-04 18:43

Hi, mindless

I would like to help. Can you give me some directions? Thanks.

I was playing with the Square Thumbnails module to get familiar with the gallery2 model system. I wanted to add a JpegTran module to gallery2 so that it can do lossless JPEG transformation.

 
mingjuwu

Joined: 2004-12-04
Posts: 10
Posted: Sat, 2004-12-04 19:26

I found that it is not necessary to have the above code modification to broke the square thumbnail. Install only the ImageMagick Graphics Tollkit and enable Square Thumbnails will do.

The image will not be croped properly.

I tried to look at the source code, but have no idea at all.
Currently still trying to understand the structure of g2.

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Sat, 2004-12-04 22:41

Here's what I wrote in the bug:

Quote:
If you can reproduce, please add some additional debug
output in GallleryFactoryHelper_simple.class to help
determine what is happening.
Lines 173-174 should ensure the class registry is populated,
and line 71 should register classes for core module,
including GalleryGroup.

put some var_dump code around those lines to figure out why it doesn't think GalleryGroup is registered.. thanks for any help you can provide.

What are the steps to reproduce the broken square thumbnail? sounds like you have a cropped thumbnail..

 
mingjuwu

Joined: 2004-12-04
Posts: 10
Posted: Sun, 2004-12-05 18:48

Steps to reproduce this:

1. fresh install of 2004-11-04's snap shot (2004-11-05 won't install for me)
2. select ImageMagick as the only Graphics Toolkit
3. select Square Thumbnails module
4. upload picture
5. get weird thumbnail or no thumbnail at all (get a broken blue glass).

FreeBSD 5.3
apache-2.0.52_3
php4-4.3.9
ImageMagick-6.0.6.2

here is a sample installation:
http://mjbsd.mjwu.net/~michael/gallery2-bk/main.php

Thank you.

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7994
Posted: Mon, 2004-12-06 00:06

I think that this is an ImageMagick issue, but I'm not sure. Would it be possible to get ssh access to your box so that we can try to reproduce the issue directly? That'll save a lot of back and forth in the forums...

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7994
Posted: Mon, 2004-12-06 08:54

mingjuwu gave me ssh access and I reproduced and fixed the bug with activating the thumbnail module. Thanks, minjuwu!

As for the ImageMagick issue, I can reproduce this on my box. With only the square thumbnail module and ImageMagick activated, I uploaded a 710x634 JPEG. The operations that it ran were:

convert -quality 75 -crop 634x634+38+0 -geometry 150x150 FILE1 FILE2

I wind up with a 112x134 JPG. If I break it up into two operations:

convert -quality 75 -crop 634x634+38+0 FILE1 FILE2
convert -geometry 150x150 FILE2 FILE3

then I wind up with a 150x150 JPG. This is with ImageMagick 6.0.6 11/29/04. It works fine with NetPBM. Didn't test GD.

mindless, it seems like this might be caused by your "smush imagemagick down to 1 operation" optimization?

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Mon, 2004-12-06 17:13

does anyone understand imagemagick's command line parameters? i already changed it to remove the -size parameter when a -crop is involved, as that was causing problems, but now with im6 it's even having trouble with -geometry? if anyone knows the proper parameters i can try to fix this..

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7994
Posted: Thu, 2004-12-09 00:23

Argh. I haven't looked at the context code, yet. But from what I understand, it would be possible to split off the -geometry operation into a separate convert call if we want, right? (as a workaround to this problem for now).

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Thu, 2004-12-09 01:21

any step along the way can choose to exec something rather than queueing parameters... so the crop can call convert to just crop and then the subsequent thumbnail operation will have nothing to do but resize with another convert call.. but come on, is there no correct set of parameters to crop and resize in one call? is this problem im6 specific?

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Fri, 2004-12-17 17:02

i filed a bug so we don't forget about this.

 
CSpotkill

Joined: 2004-12-11
Posts: 113
Posted: Fri, 2004-12-17 17:19
Quote:
Options are processed in command line order. Any option you specify on the command line remains in effect for the set of images that follows, until the set is terminated by the appearance of any option or -noop. Some options only affect the decoding of images and others only the encoding. The latter can appear after the final group of input images.

So in theory, the following should work for crop + resize:

convert -size 150x120 bigimage.jpg -crop 120x120+30+0 -resize 120x120 +profile "*" thumbnail.jpg

I think the Geometry problem has to do with the default behaviour of -geometry:

Quote:
By default, the width and height are maximum values. That is, the image is expanded or contracted to fit the width and height value while maintaining the aspect ratio of the image. Append an exclamation point to the geometry to force the image size to exactly the size you specify. For example, if you specify 640x480! the image width is set to 640 pixels and height to 480.

 
baschny
baschny's picture

Joined: 2003-01-04
Posts: 328
Posted: Sat, 2004-12-18 15:40

CSpotkill, problem is, is isn't consistent on all imagemagick versions. We have no problem with IM4 through 5.x, but IM6 it just doesn't work.

Have you managed to crop and resize in one step with Imagemagick 6? The above command line on IM 6.0.7 ignores the crop specifications.

And the -resize parameter isn't known in IM<6.x.

 
CSpotkill

Joined: 2004-12-11
Posts: 113
Posted: Sat, 2004-12-18 21:07

Well, here's the results from a little experimentation with ImageMagick 6.1.6 Q8 on Windows:

convert -quality 75 -crop 200x200+0+0 -geometry 150x160 images\ImageMagick.jpg images\logo.jpg

convert -quality 75 -crop 200x200+0+0 -geometry 150x160! images\ImageMagick.jpg images\logo2.jpg

logo.jpg - 150x155
logo2.jpg - 150x160

Notice the difference? As I wrote before this ...

CSpotkill wrote:
I think the Geometry problem has to do with the default behaviour of -geometry:

Quote:
By default, the width and height are maximum values. That is, the image is expanded or contracted to fit the width and height value while maintaining the aspect ratio of the image. Append an exclamation point to the geometry to force the image size to exactly the size you specify. For example, if you specify 640x480! the image width is set to 640 pixels and height to 480.

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Sat, 2004-12-18 21:33

how does that test apply to the problem reported here? i don't think we have any need of that ! thing

 
CSpotkill

Joined: 2004-12-11
Posts: 113
Posted: Sat, 2004-12-18 21:47

Uh. The problem was that it wasn't resizing properly. It only resized properly when the command was split in two, putting the -geometry switch as another command ...

I was showing how to resize and crop in one step, with the desired output size.

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7994
Posted: Sun, 2004-12-19 01:16

I didn't know about the exclamation mark modifier. That's cool. It didn't work for me, though:

$ convert | head -1
Version: ImageMagick 6.0.6 09/05/04 Q16 http://www.imagemagick.org
$ identify ALIVE.JPG
ALIVE.JPG JPEG 710x634 DirectClass 63kb 0.000u 0:01
$ convert -crop 634x634+38+0 -geometry 150x150 ALIVE.JPG out.jpg
$ identify out.jpg
out.jpg JPEG 112x134 DirectClass 5kb 0.000u 0:01
$ rm out.jpg
$ convert -crop 634x634+38+0 -geometry 150x150! ALIVE.JPG out.jpg
$ identify out.jpg                                               
out.jpg JPEG 112x150 DirectClass 5kb 0.000u 0:01

The result of the first operation should have given the transitional image a 1:1 aspect ratio, but both times it wound up with the wrong one (83:100 and 74:100). My guess is that ImageMagick isn't tracking the fact that the crop changed the aspect ratio, and is adjusting for the original aspect ratio (though I haven't tried to hard to make the math work out on that hypothesis).

I tried using a subsection instead:

$ convert -resize 150x150 "ALIVE.JPG[634x634+38+0]" out.jpg
$ identify out.jpg
out.jpg JPEG 150x134 DirectClass 6kb 0.000u 0:01

No joy. I filed a bug about it in their forums. Let's see what happens.

 
CSpotkill

Joined: 2004-12-11
Posts: 113
Posted: Sun, 2004-12-19 05:28

Try convert -crop 634x634+38+0 ALIVE.JPG out.jpg -geometry 150x150! ALIVE.JPG out.jpg

It's more of a workaround than doing it all in one go, but it's one execution, still ...

CSpotkill wrote:
Options are processed in command line order. Any option you specify on the command line remains in effect for the set of images that follows, until the set is terminated by the appearance of any option or -noop. Some options only affect the decoding of images and others only the encoding. The latter can appear after the final group of input images.

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7994
Posted: Sun, 2004-12-19 18:54
$ convert -crop 634x634+38+0 ALIVE.JPG out.jpg -geometry 150x150! ALIVE.JPG out.jpg
convert: unable to open image `out.jpg': No such file or directory.
$ identify out.*
out.jpg.0 JPEG 112x150 DirectClass 5kb 0.008u 0:01
out.jpg.1[1] JPEG 710x634 DirectClass 62kb 0.000u 0:01

No joy. Without the exclamation point:

$ convert -crop 634x634+38+0 ALIVE.JPG out.jpg -geometry 150x150 ALIVE.JPG out.jpg 
convert: unable to open image `out.jpg': No such file or directory.
$ identify out*
out.jpg.0 JPEG 112x134 DirectClass 5kb 0.008u 0:01
out.jpg.1[1] JPEG 710x634 DirectClass 62kb 0.000u 0:01

Still no joy. Without the second ALIVE.JPG:

$ convert -crop 634x634+38+0 ALIVE.JPG out.jpg -geometry 150x150 out.jpg
convert: unable to open image `out.jpg': No such file or directory.
$ identify out*
out.jpg JPEG 112x134 DirectClass 5kb 0.008u 0:01

It doesn't seem to like the out.jpg argument in the middle...

 
nicokaiser

Joined: 2004-10-04
Posts: 118
Posted: Mon, 2005-04-04 07:22

Any news on this subject? Gallery 2 with square thumbnails and ImageMagick does not seem to work, still...

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7994
Posted: Tue, 2005-04-05 03:33

Unfortunately, no news here. It's still open as a bug and we'll get to it when we can...

 
doctormord
doctormord's picture

Joined: 2005-01-26
Posts: 63
Posted: Tue, 2005-04-05 09:02

It works always with the "BuildAllDerivatives.php" script.

(Linux: Debian Woody + Imagemagick)

 
nicokaiser

Joined: 2004-10-04
Posts: 118
Posted: Tue, 2005-04-05 09:27

But ImageMagick version (and apparently its syntax) changed since Woody, that's the problem...

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7994
Posted: Tue, 2005-04-26 04:38

I've just submitted a fix for this. I stopped the imagemagick module from pipelining -convert and -geometry so that we now use a temporary file; this fixes the problem with ImageMagick 6.1.x (at the expense of being a little less efficient when generating cropped thumbnails).

 
nicokaiser

Joined: 2004-10-04
Posts: 118
Posted: Tue, 2005-04-26 06:46

Great, I'll test it later this day!