0

I wrote a php script that resizes jpeg images provided by external URL. The script works well on my server with a test page, but it seems that Magento doesn't allow custom php code into product description.

Is there any way to insert that piece of code into description ?

<?php 
header('Content-Type: text/html; charset=utf-8');

$url_A = 'http:/...';
$url_B = 'http:/...';

$resizer_URL = 'http:/...';

echo '<a href="'.$url_A.'" target="_blank"><img class="scanA" src="'.$resizer_URL.'?url='.$url_A.'"/></a>
      <a href="'.$url_B.'" target="_blank"><img class="scanB" src="'.$resizer_URL.'?url='.$url_B.'"/></a>';

?>

The script code is:

<?php
// The file
$filename = $_GET['url'];

// Content type
header('Content-type: image/jpeg');

// Get new dimensions
list($width, $height) = getimagesize($filename);

$ratio = $height / $width;

$new_width = 580; 
$new_height = $new_width * $ratio;

// Resample
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

// Output
imagejpeg($image_p, null, 75);

//
imagedestroy($image_p);
imagedestroy($image);
?>

Thanks.

1 Answer 1

0

You could just edit your template if you wish to have this display for all products, if not you may have to filter what type of product, or if a custom attribute is set before running the code.

The file to edit would be (based on Magento 1.9 RWD theme)

/app/design/frontend/rwd/default/template/catalog/product/view.phtml

Obviously you have to change the path to your theme.

Then you could do something like so:

$url_A = $_product->getData('extra_url1');
$url_B = $_product->getData('extra_url2');

if($url_A != '' && $url_B != '') {
     ... do your code ...
}
8
  • Hi, i appreciate your suggestion but as you can see, the piece of php code (the first block) should be different for every product. In few words, for each product , this code should display two different images relatively to the self product.
    – Lightman
    Commented Apr 14, 2015 at 14:14
  • So you simply add 2 attributes to the product - one for each url - then you check these exists and then do your code. So you enter the 2 URLs in your Product, if they exist, your code continues and outputs something .. else it does nothing. -> I've edited my answer
    – tecjam
    Commented Apr 14, 2015 at 14:23
  • Your first answer has driven me on this way. But there is a problem, the resultant html code of php block can be displayed only before or after the long description. I can't integrate it into description body. Anyway the solution you proposed could be the good one.
    – Lightman
    Commented Apr 14, 2015 at 14:51
  • Glad I could be of help.
    – tecjam
    Commented Apr 14, 2015 at 14:55
  • Thanks for the hint. If you find another solution let me know ! :D
    – Lightman
    Commented Apr 14, 2015 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.