Just another WordPress.com weblog

Posts tagged ‘product image’

How to encode product image path in magento to image blocking

Hello All,

Below is the steps to change encoded path of image and display in listing page of magento

1) Add below funciton in Image.php project/app/Local/Mage/Catalog/Helper/Image.php
Copy the core file and place in local folder and than add the code in local file.

/*********Function added to encrypt image path**********/

public function base64_encode_image ($filename=string,$filetype=string) {
if ($filename) {

$changeFilePath = explode(‘cache’,$filename);
$changeFilePath = Mage::getBaseDir(). DS. ‘media’. DS. ‘catalog’.DS.’products’.DS.’cache’.$changeFilePath[1];

$imgbinary = fread(fopen($changeFilePath, “r”), filesize($changeFilePath));
return ‘data:image/’ . $filetype . ‘;base64,’ . base64_encode($imgbinary);
}
}

Now we will call above function in list.phtml file of project/app/design/catalog/product/list.phtml

Add below inside foreach loop

<?php
$this->helper('catalog/image')->init($_product, 'small_image')->resize(193,250);
$forFiletype = explode('.',$product_image);
$forFiletype = array_reverse($forFiletype);
$filetype = $forFiletype[0];
if(strtoupper($filetype) == 'JPG')
{
$filetype = 'jpeg';
}
$base64image = '';
$base64image = $this->helper('catalog/image')->base64_encode_image($product_image,$filetype);

?>

And change Image tag of product same as Below:


<img src="<?php echo $this->getSkinUrl('images/spacer.png'); ?>" width="193" height="250" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" style="background:url(<?php echo $base64image;?>) no-repeat;"/>

When user save image it will save spacer image and not the original image.

I hope this post is helpful to you. If you have any question leave the comment.

Thanks,
Bijal Bhavsar 🙂

How to change ‘product ‘ directory name from media path in magento 1.4*

Hello All,

I found the way to rename product image folder from ‘product’ to ‘products’ or any name you wants.

1) First of all you have to rename folder name to the physical path of your project (i.e ‘project/media/catalog/product’ to ‘project/media/catalog/products’)

2) You need to change in 5 files under PATH = project/app/Mage/Catalog/Model:
You need to change from all media path ‘product’ to ‘products’ to below listed files.


file_exists(Mage::getBaseDir('media').DS.'catalog'.DS.'product'.DS.$size.DS.$image)

TO

file_exists(Mage::getBaseDir('media').DS.'catalog'.DS.'products'.DS.$size.DS.$image)

REPLACE below code

'catalog/product/'

TO
'catalog/products/'

File1: PATH / Product/Attribute/Frontend/Image.php

File2: PATH / Product/Attribute/Media/Image.php

File3: PATH / Product/Image.php

File4: PATH / Product/Media/Config.php

File5: PATH / Entity/Product/Attribute/Frontend/Image.php

I hope you will find this post helpful.. If you have any question add your comment.

Thanks,
Bijal Bhavsar 🙂