You are here:  » Seriously weird image sizes provided in feeds?

Support Forum



Seriously weird image sizes provided in feeds?

Submitted by paul30 on Mon, 2008-11-03 20:03 in

Hello David, hope all is well!

I have a few products with image sizes such as 17px by 300px, some other examples are 300px by 189px, now those are pretty big as a thumbnails so I just added "width='80'" to all of the image tags and that works for most of the "weird image sizes" as it just scales the images to 80px width and corresponding height. - My problem is with images such as 17px by 300px which are (with my solution) resized to 80px by 1412 and that looks Really bad on the pages...

My question is: Is there a known easy solution to deal with this ? I mean the ideal way would be to just scale images to 80px width if width is bigger than 80 and to 80px height if height is bigger than 80...

I do have an ability to edit products, so I am wondering if there is a known solution to this or the easiest way would be to just edit those images/products one by one replacing those images...

Cheers and thanks a lot in advance!
Pasha

Submitted by support on Mon, 2008-11-03 21:57

Hi Pasha,

As far as I know, the "best" thing you can do in this situation still has a very ugly side effect. It is possible to use a JavaScript solution that executes once the page has fully loaded; and then checks the width / height of all images only performing the scaling if required.

The big problem with this is that you have to wait until the images have loaded before doing the resize; so the user will see the large images suddenly resize - and that can (IMHO) look worse that distorted images in the first place...

Probably easier (and still worth) an email to the merchant asking for standard sized thumbnails...

Cheers,
David.

Submitted by paul30 on Tue, 2008-11-04 00:03

Ok got it thanks!

Submitted by paul30 on Tue, 2008-11-04 01:02

I have made an extensive search about this issue, and found one solution, this script will resize an image if image height OR width are bigger than a set value, which in theory is exactly the thing that is needed here, however adding this script makes pages load a LOT slower, so I am just posting it here in case someone will find a faster alternative...

Cheers
Pasha

<?php
function scale_image($p,$mw='',$mh='') { // path max_width max_height
    if(list($w,$h) = @getimagesize($p)) {
    foreach(array('w','h') as $v) { $m = "m{$v}";
        if(${$v} > ${$m} && ${$m}) { $o = ($v == 'w') ? 'h' : 'w';
        $r = ${$m} / ${$v}; ${$v} = ${$m}; ${$o} = ceil(${$o} * $r); } }
    return("<img src='{$p}' width='{$w}' height='{$h}' alt='image alt' />"); }
}
// USE EXAMPLE
echo scale_image("http://www.example.com/image.jpg");
?>