Jump to content

[SOLVED] Hiding thumbnails if image is small?


Recommended Posts

Can someone tell me how to omit the thumbnail section (on the product page) when my originally uploaded image is 300x300 or smaller?

I did some customizations to my thumbnails already but I think I can make it work with help. I'd appreciate it.

Also I'm interested in a second modification where it always hides the 'product cover' thumbnail? So that image doesn't count as a thumbnail, no matter what size the image is. So if that's the only pic, it won't show the thumbnail section at all.

(Because I would then link the 300x300 size image to the big pic. Right now the 300x300 is shown as a thumbnail which looks silly when it's the only pic and looks silly at other times too.)

Link to comment
Share on other sites

I'm not sure how you can tell the size of the original uploaded image, since the thumbnail image will always be the same size. You'd have to find a way to get the size of the non-thumbnail image. I can tell you how to remove the cover image from the thumbnails though.

Change lines 216-226 of product.php from:

foreach ($images AS $k => $image)
{
   if ($image['cover'])
   {
       $smarty->assign('mainImage', $images[0]);
       $cover = $image;
       $cover['id_image'] = intval($product->id).'-'.$cover['id_image'];
       $cover['id_image_only'] = intval($image['id_image']);
   }
   $productImages[intval($image['id_image'])] = $image;
}



to:

foreach ($images AS $k => $image)
{
   if ($image['cover'])
   {
       $smarty->assign('mainImage', $images[0]);
       $cover = $image;
       $cover['id_image'] = intval($product->id).'-'.$cover['id_image'];
       $cover['id_image_only'] = intval($image['id_image']);
   }
   list($sourceWidth, $sourceHeight) = getimagesize('img/p/'.intval($product->id).'-'.$image['id_image'].'.jpg');
   $image['width'] = $sourceWidth;
   $image['height'] = $sourceHeight;
   $productImages[intval($image['id_image'])] = $image;
}



and change lines 109-129 of product.tpl from:

{if count($images) > 0}
<!-- thumbnails -->

{if count($images) > 3}{l s='Previous'}{/if}


       {foreach from=$images item=image name=thumbnails}
       {assign var=imageIds value=`$product->id`-`$image.id_image`}

           <a href="{$link->getImageLink($product->link_rewrite, $imageIds, 'thickbox')}" rel="other-views" class="thickbox {if $smarty.foreach.thumbnails.first}shown{/if}" title="{$image.legend|htmlspecialchars}">
               <img id="thumb_{$image.id_image}" src="{$link->getImageLink($product->link_rewrite, $imageIds, 'medium')}" alt="{$image.legend|htmlspecialchars}" height="{$mediumSize.height}" width="{$mediumSize.width}" />


       {/foreach}


{if count($images) > 3}<a id="view_scroll_right" title="{l s='Other views'}" href="[removed]{ldelim}{rdelim}">{l s='Next'}{/if}

{/if}




to:

{if count($images) > 1}
<!-- thumbnails -->

{if count($images) > 4}{l s='Previous'}{/if}


       {foreach from=$images item=image name=thumbnails}
       {if $image.id_image != $cover.id_image_only}
       {assign var=imageIds value=`$product->id`-`$image.id_image`}

           {if $image.width > 300 OR $image.height > 300}
           <a href="{$link->getImageLink($product->link_rewrite, $imageIds, 'thickbox')}" rel="other-views" class="thickbox {if $smarty.foreach.thumbnails.first}shown{/if}" title="{$image.legend|htmlspecialchars}">
           {/if}
               <img id="thumb_{$image.id_image}" src="{$link->getImageLink($product->link_rewrite, $imageIds, 'medium')}" alt="{$image.legend|htmlspecialchars}" height="{$mediumSize.height}" width="{$mediumSize.width}" />
           {if $image.width > 300 OR $image.height > 300}

           {/if}

       {/if}
       {/foreach}


{if count($images) > 4}<a id="view_scroll_right" title="{l s='Other views'}" href="[removed]{ldelim}{rdelim}">{l s='Next'}{/if}

{/if}



Change [removed] to javascript followed by a :

Link to comment
Share on other sites

Thank you!

Hmm, on the other issue, it could check the size upon upload/save? And if it's small, don't bother making the 'bloated' version(s) with tons of whitespace around them? Then it could know that no thickbox size exists, just the 300x300, so skip the A HREF.

Link to comment
Share on other sites

To not generate thumbnails for products with small images won't work, since you'll end up with a lot of broken links. I'd have to think about it, but it may be possible to get the original image size of the images in product.php then pass them into product.tpl.

Link to comment
Share on other sites

For some reason the "{if $image.id_image != $cover.id_image}" doesn't change things for me. (The other two changes just being formatting.) I'm still seeing the "repeated" thumbnail of the cover image.

For the other thing... well, I don't mean skip generating thumbnails. I mean skip generating the thickbox size. Right now say my original upload is 300x300 or 290x290... it makes it into the 'large.jpg' 300x300... then it makes a thickbox.jpg that's huge like 900x900 with all that 600 pixels of white around it.

Link to comment
Share on other sites

I made another correction to my code above. The first line should be > 1, not > 0.

I've written code that gets the size of the original image and passed it into product.tpl. Should the thumbnails be hidden only if there is one image and the original size of the image is 300 x 300 pixels or less?

Link to comment
Share on other sites

It works, of course... cool :) I accidentally didn't change that >1 >0 part, lol.

Yes, thumbs would be hidden in that case due to the first mod that you wrote (never have a thumb for that one main cover image).

The difference would be... if it's 300x300 or less, don't put the thickbox link/popup. I guess that's the only difference.

Link to comment
Share on other sites

  • 5 months later...
  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...