If this is your first visit, check our documentation. To post, register or login.
Forums / Code Matters / Bug Reports / zen_image ambiguous value for $src parameter

zen_image ambiguous value for $src parameter

Started by chicagoitsystems on 19 Dec 2012, 11:25 AM · Views: 1,876

Results 1 to 7 of 7
19 Dec 2012, 11:25 AM
#1
chicagoitsystems avatar

chicagoitsystems

New Zenner

Join Date:
Jun 2010
Location:
Las Palmas de Gran Canaria, Spain
Posts:
5
Plugin Contributions:
0

Post #1 by chicagoitsystems

Hi,

First time posting but searched the site and FAQs and found no love, so here's my question/report.

Problem: The value for $src (first parameter of zen_image) is sometimes expected to be web site-relative and other times filesystem-relative

Precondition: mod_rewrite is enabled and functioning (or some other method is used to append subdirectories to store URL - e.g. http://mysite.com/store/index.php becomes http://mysite.com/store/clothes/men/index.php)

  1. call zen_image with a $src value of 'images/medium/myProductImage_MED.jpg'

Expected Result: an IMG tag with the width and height set to the actual width and height of the selected image

Actual Result: an IMG tag with width and height of the default (small) product image

Workaround: I am unaware of a way to work-around this.

I see in zen_image that there are a few calls to file_exists($src) (line 232, for example) but if the $src value provided is web site-relative (as, I assume, it should be) or if the site is using any kind of virtual file structure, such a value will always return false.

In my case I'm pretty sure the code is failing when calling @getimagesize($src) (lines 257 and 277 of includes/functions/html_output.php) and is then defaulting the the small image size. I can't think of any way to work around this and I've been racking my brain for a couple hours on this one issue.

Any suggestions/thoughts would be greatly appreciated (even including suggesting to not use zen_image).

Thanks.

Ted Stresen-Reuter
http://chicagoitsystems.com

Zen-Cart: 1.5.1
PHP 5.3.4
MySQL: 5.1.30
Apache: 2.2something
No add-ons installed
No customizations to core files

19 Dec 2012, 3:29 PM
#2
lhungil avatar

lhungil

Totally Zenned

Join Date:
Feb 2012
Location:
mostly harmless
Posts:
1,816
Plugin Contributions:
4

Post #2 by lhungil

If I remember correctly (feel free to correct me if I am wrong), Zen Cart typically expects all images to be relative to HTTP_SERVER + DIR_WS_CATALOG or HTTPS_SERVER + DIR_WS_HTTPS_CATALOG. In most of the templates a "base href" meta tag is then used to tell browsers all images and resources are relative to the value of the "base href".

There is also a define "DIR_FS_CATALOG" which should point to the root filesystem directory for your installation. You may be able to find a way to use this define (in particular when the "file_exists" and "getimagesize" functions are used).

The glass is not half full. The glass is not half empty. The glass is simply too big!
Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker

19 Dec 2012, 6:45 PM
#3
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Post #3 by kobra

Problem: The value for $src (first parameter of zen_image) is sometimes expected to be web site-relative and other times filesystem-relative
Post links to these two instances

like mysitedotcom

Zen-Venom Get Bitten

19 Dec 2012, 9:34 PM
#4
chicagoitsystems avatar

chicagoitsystems

New Zenner

Join Date:
Jun 2010
Location:
Las Palmas de Gran Canaria, Spain
Posts:
5
Plugin Contributions:
0

Post #4 by chicagoitsystems

kobra:

Post links to these two instances

like mysitedotcom

Yes, those are examples of URLs, not real ones. Would it help for you to see the resulting HTML?

19 Dec 2012, 9:46 PM
#5
chicagoitsystems avatar

chicagoitsystems

New Zenner

Join Date:
Jun 2010
Location:
Las Palmas de Gran Canaria, Spain
Posts:
5
Plugin Contributions:
0

Post #5 by chicagoitsystems

lhungil:

If I remember correctly (feel free to correct me if I am wrong), Zen Cart typically expects all images to be relative to HTTP_SERVER + DIR_WS_CATALOG or HTTPS_SERVER + DIR_WS_HTTPS_CATALOG. In most of the templates a "base href" meta tag is then used to tell browsers all images and resources are relative to the value of the "base href".

That seems reasonable. Unfortunately, I'm working on a project under a tight deadline and don't have the time to really research the methodology. It would be great to have this documented with some examples of how it should be done... But now that I look at my template, I see that indeed it's missing the base href... could be the culprit!

lhungil:

There is also a define "DIR_FS_CATALOG" which should point to the root filesystem directory for your installation. You may be able to find a way to use this define (in particular when the "file_exists" and "getimagesize" functions are used).

Right, but the reason I made this original post (and classify it as a bug) is because the incoming value of $src seems to be a URL path rather than a system path and thus it seems unlikely to work (and in fact didn't appear to work on my dev machine), but I must be missing something obvious...

Thanks for the pointers, will look into the base href option...

Ted

19 Dec 2012, 9:50 PM
#6
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Post #6 by kobra

Would it help for you to see the resulting HTML?
If you can post real url's

Zen-Venom Get Bitten

19 Dec 2012, 10:58 PM
#7
chicagoitsystems avatar

chicagoitsystems

New Zenner

Join Date:
Jun 2010
Location:
Las Palmas de Gran Canaria, Spain
Posts:
5
Plugin Contributions:
0

Post #7 by chicagoitsystems

kobra:

If you can post real url's

I can't right now because it's still in development. That said, the OR's (original responder) reminder that templates should have a base href seems to have solved the problem (in the sense that all the images are displaying properly).

What I can't quite understand, though, is how getimagesize and file_exists are returning anything other than false when sent a path that shouldn't resolve... (ponders for a moment)

On second thought, Zen-Cart is based on a "front controller" program design. I suspect the reason these functions don't fail is because they search for files relative to index.php (which "includes" all support files) and if the path is relative to the DIR_WS_CATALOG define then it should work.

So, maybe this "bug" should be closed but a "base href in all templates" requirement should be added to template documentation (if it's not already there).

Thanks a lot for helping me see the light on this. Everything seems to be working just fine now.

Sincerely,

Ted Stresen-Reuter