Forums / Developer / Creating image variations with a script...

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

eZ debug

Timing: Jan 19 2025 01:08:09
Script start
Timing: Jan 19 2025 01:08:09
Module start 'content'
Timing: Jan 19 2025 01:08:09
Module end 'content'
Timing: Jan 19 2025 01:08:09
Script end

Main resources:

Total runtime0.2448 sec
Peak memory usage4,096.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0099 589.0703180.8281
Module start 'content' 0.00990.0147 769.898498.0547
Module end 'content' 0.02470.2200 867.9531526.0000
Script end 0.2447  1,393.9531 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00421.7303200.0002
Check MTime0.00190.7631200.0001
Mysql Total
Database connection0.00120.480410.0012
Mysqli_queries0.167068.22411410.0012
Looping result0.00160.65581390.0000
Template Total0.219689.710.2196
Template load0.00140.588710.0014
Template processing0.218289.121210.2182
Override
Cache load0.00100.413510.0010
Sytem overhead
Fetch class attribute can translate value0.00090.387310.0009
XML
Image XML parsing0.00030.143010.0003
General
dbfile0.02008.1519200.0010
String conversion0.00000.003330.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs