You are here:  » PHP Image Resize


PHP Image Resize

Submitted by Eddie on Mon, 2006-11-13 15:08 in

David,

I know this works 'as is' and I was wanting to blend it into PT. My coding is poor and I just cant get it right. I know this is dependant on the merchant feed having real image files (e.g .gif/jpeg.png)

Filename : imgsize.php

Usage examples:

Resize an image to 25 x 25
imgsize.php?w=25&h=25&img=path/to/image.jpg

Resize an image to 50% the size
imgsize.php?percent=50&img=path/to/image.jpg

Resize an image to 50 pixels wide and autocompute the height
imgsize.php?w=50&img=path/to/image.jpg

Resize an image to 100 pixels tall and autocompute the width
imgsize.php?h=100&img=path/to/image.jpg

Resize to 50 pixels width OR 100 pixels tall, whichever resulting image is smaller
imgsize.php?w=50&h=100&constrain=1&img=path/to/image.jpg

Can you have a look please.

Thanks

Eddie

Submitted by support on Mon, 2006-11-13 17:21

Hi Eddie,

Assuming that imgsize.php is stored in your Price Tapestry root directory; you just need to make changes to html/searchresults.php and html/product.php as follows.

In html/searchresults.php:

Currently (line 10):

<?php print $product["image_url"]; ?>

change to:

<?php print $config_baseHREF."imgsize.php?h=100&img=".urlencode($product["image_url"]); ?>

And in html/product.php (line 7):

<?php print $mainProduct["image_url"]; ?>

change to:

$config_baseHREF."imgsize.php?h=250&img=".urlencode($mainProduct["image_url"]);

I've just picked different sizes at random there - change the 100 and 200 as required. If this doesn't work (and you are sure that you are using your image resize script correctly) then it is most likely because your server does not have URL wrappers enabled.

Cheers,
David.

Submitted by Eddie on Tue, 2006-11-14 10:08

David,

Works well - Many Thanks.

In featured.php is there any way of ignoring products if the image has height value above xx.px. The reason I ask is that the width is fine but the height sometimes of the images used is huge and breaks the formatting.

Any ideas?

Eddie
(bet your pleased I am back on PT!!! Questions galore...)

Submitted by support on Tue, 2006-11-14 10:38

Hi Eddie,

That wouldn't be practical in real time. The only way you could achieve that would be to write a script to fetch every image, check the height and then delete the product if the height is above the threshold.

Could easily look like a DoS attack on the merchant's server if you weren't careful...!

Cheers,
David.

Submitted by Eddie on Fri, 2006-11-17 14:21

David,

Works great, however (there is always one) - I have feeds that have spaces

http://www.topappliance.com/images/EW73P WHT SMALL.JPG

can you remind me how to make this as it should be as it doesnt call the image when it has spaces.

Cheers

Eddie

Submitted by support on Fri, 2006-11-17 15:13

Hi Eddie,

Spaces shouldn't be a problem because the code above uses urlencode(). Can you post the URL to a page showing a broken image that is not being displayed because of this problem - I should be able to tell from the HTML where the problem lies...

Cheers,
David.

Submitted by Eddie on Fri, 2006-11-17 17:26

David,

this does it

http://www.shopsort.co.uk/search.php?q=cooker&minPrice=&maxPrice=

Eddie

Submitted by support on Fri, 2006-11-17 17:45

Hi Eddie,

The URL is encoded correctly, and I've tried loading the image directly which works, so this must be a problem with your imgsize.php i'm afraid.

I would try adding some debug code to see what transformations are being applied between the top of the script and the point at which it fopen()'s the file (I presume that this is what it does) to see where the filename is becoming corrupted.

Cheers,
David.