How to create an image alias automatically?

Author Message

Pawel Graczyk

Friday 13 March 2009 1:20:49 pm

Is it possible to create an image alias automatically, in time when image is being uploaded?
I'm making ajax gallery. I would like to use ajax to call for image url, problem is, I cannot use attribute_view_gui() or any other template function/operator to generate my foto.

André R.

Saturday 14 March 2009 6:42:39 pm

Might help: ezoe generates image sizes for preview on demand, the code is a bit complex:
http://svn.ez.no/svn/extensions/eztinymce/trunk/ezoe/modules/ezoe/load.php
using ezoeajaxcontent.php:
http://svn.ez.no/svn/extensions/eztinymce/trunk/ezoe/classes/ezoeajaxcontent.php

related code (last line in foreach is the one triggering the image generation):

                    $content    = $atr->attribute( 'content' );
                    $imageArray = array();
                    if ( $content != null )
                    {
                        foreach( $params['imageSizes'] as $size )
                        {
                            $imageArray[ $size ] = false;
                            if ( in_array( $size, $params['imagePreGenerateSizes'] )
                                && $content->hasAttribute( $size ) )
                                $imageArray[ $size ] = $content->attribute( $size );
                        }
                        $ret['image_attributes'][] = $key;
                    }

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Pawel Graczyk

Sunday 15 March 2009 4:22:30 am

Wow, it generates JSON as well, Thank You. This code is very helpful. :)

André R.

Sunday 15 March 2009 5:21:12 am

It can also generate xml if you want to (if you use soap or xslt), and there are some more advance stuff in the ezcore extension if you need more ajax features( see http://projects.ez.no/ezcore ).

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Patrick Kaiser

Tuesday 05 May 2009 1:28:56 am

Just in case someone has also problems to use this code:

Make sure you add the ContentClass which has the image attribute you want use to the AvailableImageDataTypes[] under block [ImageDataTypeSettings] settings in site.ini:

[ImageDataTypeSettings]
AvailableImageDataTypes[]=yourCustomClassWithImageAttribute

Then the requested ImageAlias will be created on the first request. Try this in your module:

$ezAjaxOptions = array(
	'dataMap' => array('all'),
	'fetchPath' => false,
	'fetchChildrenCount' => false,
	'dataMapType' => array(),
	'loadImages' => true,
	'imagePreGenerateSizes' => array('yourCustomImageAlias')
);

$node = eZContentObjectTreeNode::fetch( $testNodeId );
$node_reduced = eZAjaxContent::simplify( $node, $ezAjaxOptions );


Best regards,

Patrick

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