Skip to main content
store number notation
Source Link
Fiasco Labs
  • 7.6k
  • 4
  • 28
  • 48

POC code that feeds out resized image url when queried with image string. For Store 1 in this sample, yours according to the given URLs is Store 0.

POC code that feeds out resized image url when queried with image string. For Store 1 in this sample.

POC code that feeds out resized image url when queried with image string. For Store 1 in this sample, yours according to the given URLs is Store 0.

script that feeds out cached image url
Source Link
Fiasco Labs
  • 7.6k
  • 4
  • 28
  • 48

POC code that feeds out resized image url when queried with image string. For Store 1 in this sample.

<?php

/*
 * imgurl.php allows you to return image url for imgquery.
 * http://www.example.com/imgurl.php?imgurl=/l/p/lp_5009.jpg
 */

ini_set('memory_limit','256M');

require_once 'app/Mage.php';
umask(0);
Mage::app()->setCurrentStore('1');
$userModel = Mage::getModel('admin/user');
$userModel->setUserId(0);


$product  = "0";
$imgurl   = "";

if (isset($_GET["imgquery"])) {  

    $string = filter_input(INPUT_GET, 'imgquery', FILTER_SANITIZE_URL);

    $imgquery = trim($string);

    $imgurl = Mage::helper('catalog/image')->init($product, 'image', $imgquery)->resize(250, 250);

}

if ($imgurl) {

    echo '<img src="' . $imgurl . '"/>';
}

?>

Feed it a get query:

http://www.example.com/imgurl.php?imgquery=/l/p/lp_5009.jpg

Which kicks out:

<img src="http://www.example.com/media/catalog/product/cache/1/image/250x250/9df78eab33525d08d6e5fb8d27136e95/l/p/lp_5009.jpg"/>

POC code that feeds out resized image url when queried with image string. For Store 1 in this sample.

<?php

/*
 * imgurl.php allows you to return image url for imgquery.
 * http://www.example.com/imgurl.php?imgurl=/l/p/lp_5009.jpg
 */

ini_set('memory_limit','256M');

require_once 'app/Mage.php';
umask(0);
Mage::app()->setCurrentStore('1');
$userModel = Mage::getModel('admin/user');
$userModel->setUserId(0);


$product  = "0";
$imgurl   = "";

if (isset($_GET["imgquery"])) {  

    $string = filter_input(INPUT_GET, 'imgquery', FILTER_SANITIZE_URL);

    $imgquery = trim($string);

    $imgurl = Mage::helper('catalog/image')->init($product, 'image', $imgquery)->resize(250, 250);

}

if ($imgurl) {

    echo '<img src="' . $imgurl . '"/>';
}

?>

Feed it a get query:

http://www.example.com/imgurl.php?imgquery=/l/p/lp_5009.jpg

Which kicks out:

<img src="http://www.example.com/media/catalog/product/cache/1/image/250x250/9df78eab33525d08d6e5fb8d27136e95/l/p/lp_5009.jpg"/>
added image helper init
Source Link
Fiasco Labs
  • 7.6k
  • 4
  • 28
  • 48

File does not exist: /home/username/public_html/domain.tld/media/catalog/product/cache/

It cleared the image cache.

media/catalog/product/F/U/

Your original images are still in place, so the clear image cache function obviously did not do as you first said, obliterates everything under /media/

Your major problem then is that your templates are not doing proper media helper calls to regenerate the image. Where exactly are you having your missing image problem?

A typical helper call asks for the url, if no URL exists, the image is added to the cache on the fly with the size chosen and then the URL is returned to the html block.

$this->helper('catalog/image')->init($_product, 'small_image')->resize(135)

Product View Page image

<img id="image" src="'.$this->helper('catalog/image')->init($_product, 'image').'" alt="'.$this->htmlEscape($this->getImageLabel()).'" title="'.$this->htmlEscape($this->getImageLabel()).'" />

Product Listing

<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />

Note that the init function for the helper takes the following inputs:

public function init(Mage_Catalog_Model_Product $product, $attributeName, $imageFile=null)

and processes $imageFile with the following:

if ($imageFile) {
    $this->setImageFile($imageFile);
} else {
    // add for work original size
$this->_getModel()->setBaseFile($this->getProduct()->getData($this->_getModel()->getDestinationSubdir()));
}

File does not exist: /home/username/public_html/domain.tld/media/catalog/product/cache/

It cleared the image cache.

media/catalog/product/F/U/

Your original images are still in place, so the clear image cache function obviously did not do as you first said, obliterates everything under /media/

Your major problem then is that your templates are not doing proper media helper calls to regenerate the image. Where exactly are you having your missing image problem?

A typical helper call asks for the url, if no URL exists, the image is added to the cache on the fly with the size chosen and then the URL is returned to the html block.

$this->helper('catalog/image')->init($_product, 'small_image')->resize(135)

Product View Page image

<img id="image" src="'.$this->helper('catalog/image')->init($_product, 'image').'" alt="'.$this->htmlEscape($this->getImageLabel()).'" title="'.$this->htmlEscape($this->getImageLabel()).'" />

Product Listing

<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />

File does not exist: /home/username/public_html/domain.tld/media/catalog/product/cache/

It cleared the image cache.

media/catalog/product/F/U/

Your original images are still in place, so the clear image cache function obviously did not do as you first said, obliterates everything under /media/

Your major problem then is that your templates are not doing proper media helper calls to regenerate the image. Where exactly are you having your missing image problem?

A typical helper call asks for the url, if no URL exists, the image is added to the cache on the fly with the size chosen and then the URL is returned to the html block.

$this->helper('catalog/image')->init($_product, 'small_image')->resize(135)

Product View Page image

<img id="image" src="'.$this->helper('catalog/image')->init($_product, 'image').'" alt="'.$this->htmlEscape($this->getImageLabel()).'" title="'.$this->htmlEscape($this->getImageLabel()).'" />

Product Listing

<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />

Note that the init function for the helper takes the following inputs:

public function init(Mage_Catalog_Model_Product $product, $attributeName, $imageFile=null)

and processes $imageFile with the following:

if ($imageFile) {
    $this->setImageFile($imageFile);
} else {
    // add for work original size
$this->_getModel()->setBaseFile($this->getProduct()->getData($this->_getModel()->getDestinationSubdir()));
}
Source Link
Fiasco Labs
  • 7.6k
  • 4
  • 28
  • 48
Loading