square thumbs?

jasonh

Joined: 2009-07-09
Posts: 31
Posted: Wed, 2009-07-15 20:47

Is there any way I can get g3 to make all my thumbs square? And not square by squishing, but square by cropping, if that makes sense. Working on a theme and I think it would be much better if all thumbs were the same size/orientation.

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16504
Posted: Wed, 2009-07-15 21:09

No, you'll need to create the plugin for that. It's not meant to be part of the core product. There is already a task made for that and I believe it's marked "Field of Dreams" meaning the core dev team has no intention of coding it themselves or it's extremely low priority if one of them happens to have an interest in that plugin. Someone else will probably need to get to it first.
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

 
jasonh

Joined: 2009-07-09
Posts: 31
Posted: Wed, 2009-07-15 21:15

Bummer. Thanks for the info.

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16504
Posted: Wed, 2009-07-15 21:24

http://sourceforge.net/apps/trac/gallery/ticket/445
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

 
Serge D
Serge D's picture

Joined: 2009-06-11
Posts: 2466
Posted: Wed, 2009-07-15 22:06

Would it be then possible to point at the part of the code where album thumbs are built versus image thumbs?

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7994
Posted: Thu, 2009-07-16 02:27

modules/gallery/helpers/gallery_installer.php defines these rules:

    graphics::add_rule(
      "gallery", "thumb", "resize",
      array("width" => 200, "height" => 200, "master" => Image::AUTO),
      100);
    graphics::add_rule(
      "gallery", "resize", "resize",
      array("width" => 640, "height" => 480, "master" => Image::AUTO),
      100);

Note that includes the default values. When you change your settings, we remove and re-add the rules. There's no separate rule for album vs. photo thumbnail. We call graphics::generate() in modules/gallery/helpers/graphics.php to run the rules for any given item.

---
Problems? Check gallery3/var/logs
bugs/feature req's | upgrade to the latest code | use git | help! vote!

 
Serge D
Serge D's picture

Joined: 2009-06-11
Posts: 2466
Posted: Thu, 2009-07-16 04:54

I did get that far, but what puzzles me is that while photo thumbs are square one for albums are proportional.
Any hints what may cause this?

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16504
Posted: Thu, 2009-07-16 05:00

I'm not seeing that. My photos are proportional as well as the album thumbs.
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

 
Serge D
Serge D's picture

Joined: 2009-06-11
Posts: 2466
Posted: Thu, 2009-07-16 05:42

Could you visit my gallery? http://photo.dragonsoft.us

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16504
Posted: Thu, 2009-07-16 06:48

No idea. I'm using a completely unmodified B2 at the moment.
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

 
jasonh

Joined: 2009-07-09
Posts: 31
Posted: Thu, 2009-07-16 17:14

Serge your thumbs being the same size and proportions no matter the input image is what gave me the idea to ask :)

I see that they are no different now...did you change anything, or did you have some kind of funky leftover from a g2 import maybe?

 
Serge D
Serge D's picture

Joined: 2009-06-11
Posts: 2466
Posted: Fri, 2009-07-17 03:08

Yes, they are now all not in the way I want them to be... Story is as following:

a) I have square thumbs in my gallery 2. My guess from the looking at the code, import process imports data as is meaning if there is a thumb in G2 which is square, import would pick it as is. This does not apply to albums since thumbs are dynamic

b) Last night I did dump everything from thumbs and resizes folders which caused all the pictures goes bad/missing. Following up on the problem I have seen the suggestion to adjust thumb and resize dimensions on the theme options page (200->201->200, 640->639->640) and then rebuild the pictures.
Well... it did not go well because code in graphics.php does not recreate the folder structure...
Ok... after some research I did the following adjustments in modules/gallery/helpers/graphics.php (true would force folder structure):

(Update 6:28pm) - improved handling of the folder recreation

Added a new function

/**
 * Checks if folder for specified file exists otherwise creates necessary folder structure
 * @param string $path
 */
static function ensure_path($path) {
  try {
    $folder = dirname($path);
    if (!file_exists($folder)) {
      Kohana::log("error", "Missing folder detected {" . $folder . "}. Recreated." );
      mkdir($folder, 0777, true);
    }
  } catch (Exception $e) {
    // Something went wrong.
    Kohana::log("error", "Caught exception ensuring the path: {" . $path . " -> " . $folder . "}\n" . $e->getMessage() . "\n" . $e->getTraceAsString());
  }
}

Adjusted following parts of the code

static function generate...
...
if ($item->thumb_dirty) {
  $ops["thumb"] = $item->thumb_path();
  self::ensure_path($item->thumb_path());}
if ($item->resize_dirty && !$item->is_album() && !$item->is_movie()) {
  $ops["resize"] = $item->resize_path();
  self::ensure_path($item->resize_path());
}
static function resize...
...
} else {
  // ensure that folder exists
  self::ensure_path($output_file));
  Image::factory($input_file)

That may not be final solution, or could be overkill, but it does what it is suppose to do - allows recreate proper folder structure and refresh all resizes/thumbs.

This is today. Last night I have created a case http://sourceforge.net/apps/trac/gallery/ticket/550
and I am hopelessly (Field of Dreams) :) looking forward to have case http://sourceforge.net/apps/trac/gallery/ticket/445 implemented or for any information what I have to modify to force square thumbs

 
jasonh

Joined: 2009-07-09
Posts: 31
Posted: Thu, 2009-07-16 20:45

I've kind of gotten the square thumb "look" working so far...it's really just a pretty bad hack... All I did was set my thumb size to 301px (crashed on 300 for some reason and wouldn't start back up), so my 4x6 aspect ratio photos would have 200px on the short side. Then my div blocks in the theme I'm working on are set to 200x200 and the overflow is hidden. changing the vertical alignment on the images will change which portion is shown. The only time this causes a problem is when I have a photo that is cropped to a different aspect ratio.

my beta-gallery testing different techniques for a theme (so yeah, it's ugly): http://g3.jasonhight.net

It's actually a really simple fix in the command-line for ImageMagick to get what we're looking for, but I can't for the life of me find anywhere in the code that calls the actual IM binary.

 
Serge D
Serge D's picture

Joined: 2009-06-11
Posts: 2466
Posted: Thu, 2009-07-16 22:57

To say everything is here in code - classes support crop properly, but I am having difficulty as well to find where crop could be called instead of resize for thumbs...

 
jasonh

Joined: 2009-07-09
Posts: 31
Posted: Sun, 2009-07-19 17:53

For anybody interested, I've come up with a solution for those using ImageMagick:

http://gallery.menalto.com/node/89120#comment-314345

 
Serge D
Serge D's picture

Joined: 2009-06-11
Posts: 2466
Posted: Fri, 2009-07-24 20:52

Ok, will continue there