Creating image variations with a script...

Author Message

Norman Leutner

Thursday 17 August 2006 5:06:42 am

For a csv export job I need the create image variations from a objectattribute (ezimage) and return the url to the script.

Has anybody a example or a hint for me how to create them.

Thanks in advance

Mit freundlichen Grüßen
Best regards

Norman Leutner

____________________________________________________________
eZ Publish Platinum Partner - http://www.all2e.com
http://ez.no/partners/worldwide_partners/all2e_gmbh

Claudia Kosny

Friday 18 August 2006 2:01:42 pm

Hello Norman,

If you fetch the content of the contenobjectattribute of type ezimage you get an object of type eximagealiashandler. If you call the method aliasList() on this object you get some information about at least the original image, here an example:

Array
(
    [original] => Array
        (
            [name] => original
            [width] => 768
            [height] => 1024
            [mime_type] => image/jpeg
            [filename] => adapteur_k7.jpg
            [suffix] => jpg
            [dirpath] => var/shop_site/storage/images/products/adapteur_k7__1/1637-2-eng-GB
            [basename] => adapteur_k7
            [alternative_text] => 
            [text] => 
            [original_filename] => adapteur.jpg
            [url] => var/shop_site/storage/images/products/adapteur_k7__1/1637-2-eng-GB/adapteur_k7.jpg
            [alias_key] => 1293033771
            [timestamp] => 1155930595
            [full_path] => var/shop_site/storage/images/products/adapteur_k7__1/1637-2-eng-GB/adapteur_k7.jpg
            [is_valid] => 1
            [is_new] => 
            [filesize] => 93279
            [info] => 
        )
)

Unfortunately you will not always get all other aliases (this seems to depend on what aliases have been called up already, I am not sure). But as you only need the urls of the different variations I think it should be enough to fetch all possible aliasnames form the image.ini file and change the filename accordingly. For example the name of the small variation of the above pic is adapteur_k7_small.jpg.

There are most likely easier ways to do what you need but the above works for me. If you need other information have a look at the class \kernel\classes\datatypes\ezimage\ezimagealiashandler.php

Also please note that I tried this with ez 3.8.3 and I have no idea whether this works with other versions.

Greetings from Luxembourg

Claudia

Norman Leutner

Sunday 20 August 2006 12:53:36 am

Thanks for the hint,
I already found the imagealiashandler.php
The method I was looking for was imageAlias()

This is the code I use to create those thumbnails for the csv file, it returns the url of the created thumbnail.

class eZCsvImageHandler extends BaseHandler{
  function exportAttribute(&$attribute, $seperationChar) {
    $imageHandler=&$attribute->content();
    
    $imageAlias =& $imageHandler->imageAlias( 'thumbnail' );
      
    $url = eZSys::hostname() . eZSys::wwwDir() .'/'. $imageAlias['url'];
    $url = preg_replace( "#^(//)#", "/", $url );

    return 'http://'.$url;    

  }
}

Mit freundlichen Grüßen
Best regards

Norman Leutner

____________________________________________________________
eZ Publish Platinum Partner - http://www.all2e.com
http://ez.no/partners/worldwide_partners/all2e_gmbh

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.