Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Needing help changing Image Handler for a CDN (Content Delivery Network)

Needing help changing Image Handler for a CDN (Content Delivery Network)

Views: 2,275

Results 1 to 20 of 21
23 Aug 2013, 12:04 AM
#1
trinorthlighting avatar

trinorthlighting

Zen Follower

Join Date:
Aug 2005
Location:
New York!!!
Posts:
141
Plugin Contributions:
0

Needing help changing Image Handler for a CDN (Content Delivery Network)

Ok, we have been working a lot on speeding up our website and have moved to a Content Delivery Network. We currently have our js and css taken care of but are running into a brick wall in coding for the images. We are using image handler 4 for our images. Now, since we are using a cdn, our urls need to change from:

http://ledchristmaslighting.com/bmz_cache/etc....

to

http://cdn.ledchristmaslighting.com/bmz_cache/etc.

Now, we know that this code right here is what we need to change, but are not sure how to change it in php and we are asking for some help here.

public_html/includes/classes/bmz_image_handler.class.php

Line #208 : ((strpos($this->src, substr($bmzConf['cachedir'], strlen($ihConf['dir']['docroot']))) === 0))) &&

Can anyone help us out here a bit on the coding? I know this part needs to be adjusted and modified to point to our .cdn subdomain:

((strpos($this->src, substr

26 Aug 2013, 5:54 PM
#2
trinorthlighting avatar

trinorthlighting

Zen Follower

Join Date:
Aug 2005
Location:
New York!!!
Posts:
141
Plugin Contributions:
0

Re: Needing help changing Image Handler for a CDN (Content Delivery Network)

Anyone have any suggestions?

26 Aug 2013, 6:05 PM
#3
dbltoe avatar

dbltoe

Totally Zenned

Join Date:
Jan 2004
Location:
N of San Antonio TX
Posts:
9,763
Plugin Contributions:
9

Re: Needing help changing Image Handler for a CDN (Content Delivery Network)

This would have been better addressed in the support thread for Image Handler.

It appears that your site uses both cdnDOTledchristmaslighting.... and ledchristmaslighting...

You should probably redirect and decide which one to use. IH4 bases the location of the bmz_cache on the variable DIR_FS_CATALOG which is set in the config files.

Using a redirect from cdnDOT to the regular site should solve the problem.

27 Aug 2013, 6:17 AM
#4
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: Needing help changing Image Handler for a CDN (Content Delivery Network)

dbltoe:

This would have been better addressed in the support thread for Image Handler.

It appears that your site uses both cdnDOTledchristmaslighting.... and ledchristmaslighting...

You should probably redirect and decide which one to use. IH4 bases the location of the bmz_cache on the variable DIR_FS_CATALOG which is set in the config files.

Using a redirect from cdnDOT to the regular site should solve the problem.

Exactly.. this issue won't be resolved by hacking IH4 files as IH4 correctly picks up the image URL from the configuration file..

27 Aug 2013, 6:24 AM
#5
gilby avatar

gilby

Totally Zenned

Join Date:
Aug 2005
Location:
Vic, Oz
Posts:
1,816
Plugin Contributions:
0

Re: Needing help changing Image Handler for a CDN (Content Delivery Network)

Just for my interest.....
IH create images on the fly when needed and stores them in the website bmz directory.
How do you intend creating images on the fly and then uploading them to your cdn?

I suspect altering the code to refer to the cdn for image display is probably doable.
But the uploading on the fly bit is going to be a headache

27 Aug 2013, 7:10 AM
#6
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: Needing help changing Image Handler for a CDN (Content Delivery Network)

gilby:

Just for my interest.....
IH create images on the fly when needed and stores them in the website bmz directory.
How do you intend creating images on the fly and then uploading them to your cdn?

I suspect altering the code to refer to the cdn for image display is probably doable.
But the uploading on the fly bit is going to be a headache

Ahh I get it.. they want to serve the IH4 cache from the CDN versus the bmz_cache folder?? That is going to require a BIG change to IH4's core functionality, and I imagine that the code to do this will NOT be forthcoming from the forum.. Sounds like custom dev to me..

30 Aug 2013, 12:54 PM
#7
trinorthlighting avatar

trinorthlighting

Zen Follower

Join Date:
Aug 2005
Location:
New York!!!
Posts:
141
Plugin Contributions:
0

Re: Needing help changing Image Handler for a CDN (Content Delivery Network)

As far as the bmz cache goes, once that is created it is created and done. So it would seem that the easiest thing to do is change the coding on the product page to point to the url cdn.ledchristmaslighting.com

The cdn domain is not mine, that is the content delivery networks. All it does is cache items. When I point to the cdn network, it comes and gets the non cdn item and caches it multiple servers and adds the cdn. Anyways, when I look at the source code on an output page for an item it shows like this currently:

<td width="160" valign="top" class="listing-img main" align="center"> <a href="http://ledchristmaslighting.com/index.php?main_page=product_info&cPath=927_949_966&products_id=18172">********<img itemprop="image" src="bmz_cache/0/00a112c160d3ae925c462301acd2d420.image.150x120.jpg"********* alt="C-Splash 2 Light 10 degree beam angle" title=" C-Splash 2 Light 10 degree beam angle " width="150" height="120" /></a><br clear="all" /><br clear="all" />In Stock: 1000<br clear="all" /><br clear="all" /> </td>

Ok, so I do not want to modify when image handler changes the photo, I just want to modify the source code in the php to reflect what is listed below between the *******

<td width="160" valign="top" class="listing-img main" align="center"> <a href="http://ledchristmaslighting.com/index.php?main_page=product_info&cPath=927_949_966&products_id=18172">******<img itemprop="image" src="//cdn.ledchristmaslighting.com/bmz_cache/0/00a112c160d3ae925c462301acd2d420.image.150x120.jpg"******* alt="C-Splash 2 Light 10 degree beam angle" title=" C-Splash 2 Light 10 degree beam angle " width="150" height="120" /></a><br clear="all" /><br clear="all" />In Stock: 1000<br clear="all" /><br clear="all" /> </td>
30 Aug 2013, 2:01 PM
#8
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: Needing help changing Image Handler for a CDN (Content Delivery Network)

trinorthlighting:

As far as the bmz cache goes, once that is created it is created and done. So it would seem that the easiest thing to do is change the coding on the product page to point to the url cdn.ledchristmaslighting.com

The cdn domain is not mine, that is the content delivery networks. All it does is cache items. When I point to the cdn network, it comes and gets the non cdn item and caches it multiple servers and adds the cdn. Anyways, when I look at the source code on an output page for an item it shows like this currently:

<td width="160" valign="top" class="listing-img main" align="center"> <a href="http://ledchristmaslighting.com/index.php?main_page=product_info&cPath=927_949_966&products_id=18172">********<img itemprop="image" src="bmz_cache/0/00a112c160d3ae925c462301acd2d420.image.150x120.jpg"********* alt="C-Splash 2 Light 10 degree beam angle" title=" C-Splash 2 Light 10 degree beam angle " width="150" height="120" /></a><br clear="all" /><br clear="all" />In Stock: 1000<br clear="all" /><br clear="all" /> </td>

Ok, so I do not want to modify when image handler changes the photo, I just want to modify the source code in the php to reflect what is listed below between the *******

<td width="160" valign="top" class="listing-img main" align="center"> <a href="http://ledchristmaslighting.com/index.php?main_page=product_info&cPath=927_949_966&products_id=18172">******<img itemprop="image" src="//cdn.ledchristmaslighting.com/bmz_cache/0/00a112c160d3ae925c462301acd2d420.image.150x120.jpg"******* alt="C-Splash 2 Light 10 degree beam angle" title=" C-Splash 2 Light 10 degree beam angle " width="150" height="120" /></a><br clear="all" /><br clear="all" />In Stock: 1000<br clear="all" /><br clear="all" /> </td>

and I stand by my previous response to this.. You are talking about the image caching function of IH4. You want it to store this image cache on your CDN versus a local folder as it does now. This is a KEY part of IH4s core functionality, and it IS going to require a BIG change to IH4's core code (ie: it's not a simple ONE FILE change).. This is CUSTOM development, and you are probably going to need to hire someone to make this modification for you.. I suspect that the code to do this will NOT be forthcoming (ie: for free) from the forum.

2 Sep 2013, 11:28 PM
#9
trinorthlighting avatar

trinorthlighting

Zen Follower

Join Date:
Aug 2005
Location:
New York!!!
Posts:
141
Plugin Contributions:
0

Re: Needing help changing Image Handler for a CDN (Content Delivery Network)

I can not store the images on the cdn vs the local folder anyways because of image handler. The coding should be easier to change in zencart than rather changing the IH4 core code. I also have been considering a simple 301 redirect for all images as well.

3 Sep 2013, 12:16 AM
#10
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: Needing help changing Image Handler for a CDN (Content Delivery Network)

trinorthlighting:

I can not store the images on the cdn vs the local folder anyways because of image handler. The coding should be easier to change in zencart than rather changing the IH4 core code. I also have been considering a simple 301 redirect for all images as well.
The PRIMARY purpose of IH4 is to compress and cache the images.. the IH4 image cache is a local directory called bmz_cache.. how do you propose you have images with a URL of cdn.yourdomain.com/bmz_cache/....... without images being stored on the CDN??

3 Sep 2013, 12:39 AM
#11
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Needing help changing Image Handler for a CDN (Content Delivery Network)

trinorthlighting,
Please take this post as the constructive feedback for which it is intended.

While on the surface it might sound like it's as simple as pointing things to a different URL, IH completely changes the ZC image handling.
So what you're asking for is not a ZC core code change. It's an IH code change.

So ... ya, if what you really want is to change its functionality, feel free to change the PHP code to do that. You'll lose all the sanity checking that it does about the image file actually existing, unless you build in a check to have it actually look at the CDN server and verify the presence of the required image file (which adds increased delays on every check for every image), you'll also end up with broken image links on your pages anytime you make an image adjustment.

So then there's the issue of keeping the CDN up-to-date with new images added. While on the surface you may think it's as easy as periodically uploading changes, you'll have to code for it to handle when an image is missing, as hinted at in my last paragraph.
Your post implies that whatever CDN you've chosen apparently does all this self-updating automatically. That's not the norm. And a proper solution should be more sophisticated, such as actually intentionally pushing changes to the CDN when changes are made, not forcing it to "discover" during failures, which results in poor end-user experience.

Those are just the beginning of the changes. Can it be done? Sure! Are there LOTS of things to consider from LOTS of angles? Yup!

So, back to my first comment: on the surface one might think it's as easy as changing URLs. Feel free to start there. Everyone here is telling you that it's much more complex than that, and they know that there's no point in telling you only how to do that, because it will just break things on you. Nobody's trying to be rude or disrespectful. Just realistic.
You need to hire someone who's willing to take the time to study the implications of your proposed changes and then code things to work as you desire.

Then there's the issue of "why" you're even looking at this in the first place. There are some poorly-tuned servers that simply can't serve images well, and in those cases a CDN might help, but it's really a bandage.
There are also those in the camp of "use a cookieless domain to serve images because it'll improve speed by XY%", and even Google used to suggest this, but have relaxed their recommendations for this with the improvements in modern-day servers which can serve content just fine from the same domain. So people following this path based on that reasoning are largely following aging seo advice. Not that it's obsolete, but it doesn't pack the punch it used to. It's actually slower to load images from multiple domains because of the latency required to look up the address of those other domains.
And, yup, there are two opposing camps on these so-called seo-tweaks. Half of them are right. Half of them are in both camps. Half of them use crap servers so are looking at the wrong problem in the first place.

I'm not saying what you're attempting is wrong or pointless. I'm saying to make sure you're prepared to do it correctly if you do it, and to review it again and again every 3 months to be 1000% sure it's actually giving you something good, and that you're testing it on as many relevant browsers as possible. Because it might be wasted effort.

Just don't follow the flavor-of-the-month because it's popular or because some self-proclaimed guru said it's the best thing since sliced break. Make sure you have empirical evidence to guarantee the value of what you're about to do. This applies to everything, not just the subject at hand.

As far as doing what you started posting about, look at the IH code (you can see exactly which files are involved by looking at the plugin zip itself), and go from there. Little point in stepping out of that into ZC core since IH intercepts that almost exclusively.

3 Sep 2013, 1:12 AM
#12
gilby avatar

gilby

Totally Zenned

Join Date:
Aug 2005
Location:
Vic, Oz
Posts:
1,816
Plugin Contributions:
0

Re: Needing help changing Image Handler for a CDN (Content Delivery Network)

DrByte:

Make sure you have empirical evidence to guarantee the value of what you're about to do. This applies to everything, not just the subject at hand.
Hear Hear...
You need to have a very good business plan to want to attempt this.

I suspect that the results will be disappointing,
even without considering the amount of custom programming required.

3 Sep 2013, 3:02 AM
#13
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: Needing help changing Image Handler for a CDN (Content Delivery Network)

DrByte:

trinorthlighting,
Please take this post as the constructive feedback for which it is intended.

While on the surface it might sound like it's as simple as pointing things to a different URL, IH completely changes the ZC image handling.
So what you're asking for is not a ZC core code change. It's an IH code change.

So ... ya, if what you really want is to change its functionality, feel free to change the PHP code to do that. You'll lose all the sanity checking that it does about the image file actually existing, unless you build in a check to have it actually look at the CDN server and verify the presence of the required image file (which adds increased delays on every check for every image), you'll also end up with broken image links on your pages anytime you make an image adjustment.

So then there's the issue of keeping the CDN up-to-date with new images added. While on the surface you may think it's as easy as periodically uploading changes, you'll have to code for it to handle when an image is missing, as hinted at in my last paragraph.
Your post implies that whatever CDN you've chosen apparently does all this self-updating automatically. That's not the norm. And a proper solution should be more sophisticated, such as actually intentionally pushing changes to the CDN when changes are made, not forcing it to "discover" during failures, which results in poor end-user experience.

Those are just the beginning of the changes. Can it be done? Sure! Are there LOTS of things to consider from LOTS of angles? Yup!

So, back to my first comment: on the surface one might think it's as easy as changing URLs. Feel free to start there. Everyone here is telling you that it's much more complex than that, and they know that there's no point in telling you only how to do that, because it will just break things on you. Nobody's trying to be rude or disrespectful. Just realistic.
You need to hire someone who's willing to take the time to study the implications of your proposed changes and then code things to work as you desire.

Then there's the issue of "why" you're even looking at this in the first place. There are some poorly-tuned servers that simply can't serve images well, and in those cases a CDN might help, but it's really a bandage.
There are also those in the camp of "use a cookieless domain to serve images because it'll improve speed by XY%", and even Google used to suggest this, but have relaxed their recommendations for this with the improvements in modern-day servers which can serve content just fine from the same domain. So people following this path based on that reasoning are largely following aging seo advice. Not that it's obsolete, but it doesn't pack the punch it used to. It's actually slower to load images from multiple domains because of the latency required to look up the address of those other domains.
And, yup, there are two opposing camps on these so-called seo-tweaks. Half of them are right. Half of them are in both camps. Half of them use crap servers so are looking at the wrong problem in the first place.

I'm not saying what you're attempting is wrong or pointless. I'm saying to make sure you're prepared to do it correctly if you do it, and to review it again and again every 3 months to be 1000% sure it's actually giving you something good, and that you're testing it on as many relevant browsers as possible. Because it might be wasted effort.

Just don't follow the flavor-of-the-month because it's popular or because some self-proclaimed guru said it's the best thing since sliced break. Make sure you have empirical evidence to guarantee the value of what you're about to do. This applies to everything, not just the subject at hand.

As far as doing what you started posting about, look at the IH code (you can see exactly which files are involved by looking at the plugin zip itself), and go from there. Little point in stepping out of that into ZC core since IH intercepts that almost exclusively.thanks DrByte for stepping in here..

3 Sep 2013, 7:35 PM
#14
trinorthlighting avatar

trinorthlighting

Zen Follower

Join Date:
Aug 2005
Location:
New York!!!
Posts:
141
Plugin Contributions:
0

Re: Needing help changing Image Handler for a CDN (Content Delivery Network)

Ok, we have a 301 redirect that does work, but that is not what we really want to do. There is no reason why we really have to use image handler (the reason we were was for image compression, but we can take care of that another way), so we can actually stop using that.

So, if we did drop the image handler and were just using the image folder what about making a simple change to the configure.php file pointing towards the subdomain?

3 Sep 2013, 8:06 PM
#15
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Needing help changing Image Handler for a CDN (Content Delivery Network)

trinorthlighting:

So, if we did drop the image handler and were just using the image folder what about making a simple change to the configure.php file pointing towards the subdomain?
You'd still have to rewrite the ZC core code that specifically deals with image dimensions/sizing because ZC bases that on the physical image file, and since you're saying you don't want those on your server then ZC won't be able to do that, and you'll need to have it skip everything it does with local files while preparing the HTML for the image tag output. And then have ZC specifically use a URL ... because the core code does NOT use absolute URLs for image tags ... it treats them as relative to your store.

3 Sep 2013, 8:15 PM
#16
trinorthlighting avatar

trinorthlighting

Zen Follower

Join Date:
Aug 2005
Location:
New York!!!
Posts:
141
Plugin Contributions:
0

Re: Needing help changing Image Handler for a CDN (Content Delivery Network)

Ok, you confused me Dr Byte. We would not need to resize the images and the images would be on our server when we dropped the image handler. I am sorry if I confused you.

What we were thinking is in the configure.php file is making a change to this code and pointing the images to the cdn server.

define('DIR_WS_IMAGES', 'images/');

3 Sep 2013, 8:34 PM
#17
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Needing help changing Image Handler for a CDN (Content Delivery Network)

That's only a small part of the equation.
Like I said in an earlier post, while it might seem to be that simple, there's more going on under the hood than just specifying a path.
If you change that to a URL like http://cdn.example.com then you'll be telling your Zen Cart to evaluate physical files on your server located at /var/home/username/public_html/http://cdn.example.com/images/file.jpg when it attempts to verify the presence of the file (so that it can take action if the file is not present) and when it checks the file's dimensions in order to generate the width/height attributes of the img tag, and so on.
So, you'll have to rewrite the code and hack out the part that does any validation since your images won't be on your ZC server and thus it won't have the ability to do any of those checks. Basically you're dumbing-down the code to what it did in an alpha before the very first release a decade ago.

Plus then you'll need to change your admin image-upload logic to push the files to the CDN instead of to the local ZC server. And then change the way the admin displays product images by telling it where to find them on the CDN. That code is similar, but different than the code on the storefront.

3 Sep 2013, 9:17 PM
#18
trinorthlighting avatar

trinorthlighting

Zen Follower

Join Date:
Aug 2005
Location:
New York!!!
Posts:
141
Plugin Contributions:
0

Re: Needing help changing Image Handler for a CDN (Content Delivery Network)

With CDN becoming popular and the price dropping, zen should really consider this in future updates. Considering that images are the bulk of the content for a lot of zen websites (86% of the content on an average page on our site is images) it is something to consider. In todays market it is all about speed on eccomerce and to sell world wide the CDN makes sense since the servers are spread around the world. Also, the CDN takes a lot of requests away from your server since the images are cached on other servers. This frees up resources on the server to deal with other requests and speeds things up in general.

3 Sep 2013, 10:26 PM
#19
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Needing help changing Image Handler for a CDN (Content Delivery Network)

Yup. You've been heard. And so have the others who view it from the opposite angle.

3 Sep 2013, 10:50 PM
#20
trinorthlighting avatar

trinorthlighting

Zen Follower

Join Date:
Aug 2005
Location:
New York!!!
Posts:
141
Plugin Contributions:
0

Re: Needing help changing Image Handler for a CDN (Content Delivery Network)

Besides the coding changes, I am not really sure what you mean by people with the opposite angle. Website speed is good, you may say get a faster server, but when your website is getting a lot of traffic already and your server is already topped out, what else can you do?

Imagine how much a cdn can cut bandwidth. We did a quick study and this website alone if we can get the images to pull from the cdn we can save over 40GB of bandwidth daily which is a lot.