Site maintenance: Sun 15 Nov, from 12:00 UTC, about 4–6 hours. Details

This cutover relies on some testing that is still incomplete so may be cancelled at short notice

Call Larger Images

Locked

Started by goetch on 8 Aug 2012, 5:50 PM · Views: 829

Results 1 to 4 of 4
This thread is locked. New replies are disabled.
8 Aug 2012, 5:50 PM
#1
goetch avatar

goetch

New Zenner

Join Date:
Dec 2009
Posts:
37
Plugin Contributions:
0

Call Larger Images

Hi, I have searched the forum all morning and have not found the answer to this question, however, I apologize if this question has been already asked. On my current site I only use small and large images. I have installed a facebook like button for my products (that works great by the way) however I have one small problem with it... My small images are 150 x 150 and facebook is telling me that my images should be at least 200 x 200. I would like to call the large image instead of the small image. I have been trying to dig into the php files to try to figure this out however I think I am too much a noob with php... I think I know how to do it I just do not know the proper code to get it done...... Here is my current facebook image code... ```

<?php if (isset($_GET['products_id'])) { // use products_image if products_id exists $facebook_image = $db->Execute("select p.products_image from " . TABLE_PRODUCTS . " p where products_id='" . (int)$_GET['products_id'] . "'"); $fb_image = HTTP_SERVER . DIR_WS_CATALOG . DIR_WS_IMAGES . $facebook_image->fields['products_image']; } if ($fb_image == '') { // if no products image, use the default image if enabled $fb_image = 'http://www.store.com/includes/templates/scb/images/logo.gif'; } if ($fb_image != '') { ?> <meta property="og:image" content="<?php echo $fb_image; ?>" /> ```

I tried a few things to get the larger image to appear and managed to get to the correct directory and what would be the correct image if it did have the _lrg tag on it... I assume there is a way in php to add the _lrg tag to the end of the image name (before the extension) I just do not know how to do this properly.....

8 Aug 2012, 6:28 PM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,511
Plugin Contributions:
176

Re: Call Larger Images

Goetch:

Here is my current facebook image code... ```

<?php if (isset($_GET['products_id'])) { // use products_image if products_id exists $facebook_image = $db->Execute("select p.products_image from " . TABLE_PRODUCTS . " p where products_id='" . (int)$_GET['products_id'] . "'"); $fb_image = HTTP_SERVER . DIR_WS_CATALOG . DIR_WS_IMAGES . $facebook_image->fields['products_image']; } if ($fb_image == '') { // if no products image, use the default image if enabled $fb_image = 'http://www.store.com/includes/templates/scb/images/logo.gif'; } if ($fb_image != '') { ?> <meta property="og:image" content="<?php echo $fb_image; ?>" /> ``` I'd be inclined to replace all that with this instead:``` <?php // default image: $fb_image = HTTP_SERVER . DIR_WS_CATALOG . 'includes/templates/scb/images/logo.gif'; if (isset($_GET['products_id'])) { // use products_image if products_id exists $facebook_image = $db->Execute("select p.products_image from " . TABLE_PRODUCTS . " p where products_id='" . (int)$_GET['products_id'] . "'"); $prod_image = $facebook_image->fields['products_image']; $prod_image_extension = substr($prod_image, strrpos($prod_image, '.')); $prod_image_base = str_replace($prod_image_extension, '', $prod_image); $prod_image_large = $prod_image_base . IMAGE_SUFFIX_LARGE . $prod_image_extension;

if (file_exists(DIR_WS_IMAGES . 'large/' . $prod_image_large)) {
$prod_image = DIR_WS_IMAGES . 'large/' . $prod_image_large;
}
$fb_image = HTTP_SERVER . DIR_WS_CATALOG . $prod_image;
}
if ($fb_image != '') {
?>
<meta property="og:image" content="<?php echo $fb_image; ?>" />

<?php } ?>
Then it reads the image from the database, parses it into its parts, inserts the "lrg" bit, checks if the file exists, and if it does, then it replaces the value set as default earlier.
Then it carries on to output it as you were doing before.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

8 Aug 2012, 6:36 PM
#3
goetch avatar

goetch

New Zenner

Join Date:
Dec 2009
Posts:
37
Plugin Contributions:
0

Re: Call Larger Images

Your the best thank you so much!!!! Very helpful!!!

8 Aug 2012, 6:37 PM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,511
Plugin Contributions:
176

Re: Call Larger Images

Actually, since the system has already determined the available images, you could probably save the database query and the more complex logic, and just use the already-available information, like this instead:

<?php
$fb_image = HTTP_SERVER . DIR_WS_CATALOG . 'includes/templates/scb/images/logo.gif';
if ($products_image_large != '') $fb_image = HTTP_SERVER . DIR_WS_CATALOG . $products_image_large;
?>
<meta property="og:image" content="<?php echo $fb_image; ?>" />

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.