
Originally Posted by
shinypenguin
Does anyone know how to retrieve the path for a cached image in the header? (implementing in the includes/templates/{template}/common/html_header.php file)
Since this is before the page templates are included, I'm assuming there are some files that need to be required, and there must be a function or something to retrieve the cached path as it's done on the products page.
I'm hoping this is fairly simple for someone that understands Image Handler better - I've spent several hours looking through the files and about to the point of giving up. The couple threads found on this site and through Google were unanswered.
Any help would be greatly appreciated!
Additional background:
This is for implementing the meta tags for a Facebook "like" button on product pages to avoid outputting the original image path (full sized without a watermark) in the header where it can be read from the source code and accessed directly. Also, depending on the frequency of Facebook checking, the full size 1.5-2mb pictures would eat up a lot of unnecessary bandwidth.
This will only be used on product info pages, and it can be assumed I'm running a freshly installed zen cart 1.3.9h with Image Handler 3. The product name, original picture path, and other information from the products table are stored in variables that can be used for retrieval.
None of the implementation code beyond finding the cache path is needed.
Figures! After writing up the post, I finally figured out what was going wrong.
The full implementation is quite convoluted, but it turned out all the needed files were already included... I will just share the part I was having difficulty with - retrieving the cache path after having the original image path. Hopefully it will save someone else time because it certainly took up a lot of mine!
This code is in the includes/modules/meta_tags.php file. The only required prior modification is adjusting the sql query around line 194 to also retrieve p.products_image. "FB" is attached to all variables to avoid any conflicts. The cached path is stored as META_TAG_FBIMG_CACHE so it can be retrieved in the html_header.php file:
PHP Code:
$FBproducts_image = $product_info_metatags->fields['products_image'];
$FBproducts_image_extension = substr($FBproducts_image, strrpos($FBproducts_image, '.'));
$FBproducts_image_base = preg_replace('/'.$FBproducts_image_extension . '$/', '', $FBproducts_image);
$FBproducts_image_medium = DIR_WS_IMAGES . 'medium/' . $FBproducts_image_base . IMAGE_SUFFIX_MEDIUM . $FBproducts_image_extension;
$FBnewimg = handle_image($FBproducts_image_medium, '', MEDIUM_IMAGE_WIDTH, MEDIUM_IMAGE_HEIGHT, '');
list($FBsrc, $FBalt, $FBwidth, $FBheight, $FBparameters) = $FBnewimg;
define('META_TAG_FBIMG_CACHE', (($request_type == 'SSL') ? HTTPS_SERVER . DIR_WS_HTTPS_CATALOG : HTTP_SERVER . DIR_WS_CATALOG ).$FBsrc);
Warning:
1. I implemented this using Image Handler 2, but the functions used in this look about the same from what I can tell.
2. This has not been completely tested or optimized, and it could very likely cause errors under unknown circumstances. I did not test it at all on secure pages, since my product pages are all http. It does have a code snippet that should insert https where required to avoid SSL warnings, but if you encounter them, this code is likely the cause.
Bookmarks