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.

eZ debug

Timing: Jan 18 2025 18:42:50
Script start
Timing: Jan 18 2025 18:42:50
Module start 'layout'
Timing: Jan 18 2025 18:42:50
Module start 'content'
Timing: Jan 18 2025 18:42:50
Module end 'content'
Timing: Jan 18 2025 18:42:50
Script end

Main resources:

Total runtime0.5250 sec
Peak memory usage4,096.0000 KB
Database Queries65

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0069 588.0469152.6406
Module start 'layout' 0.00690.0040 740.687539.4766
Module start 'content' 0.01090.5120 780.1641603.9766
Module end 'content' 0.52290.0020 1,384.140616.1250
Script end 0.5249  1,400.2656 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00350.6585160.0002
Check MTime0.00140.2607160.0001
Mysql Total
Database connection0.00130.243310.0013
Mysqli_queries0.463888.3520650.0071
Looping result0.00070.1385630.0000
Template Total0.482992.020.2414
Template load0.00240.466520.0012
Template processing0.480491.515220.2402
Template load and register function0.00020.034810.0002
states
state_id_array0.00811.550010.0081
state_identifier_array0.00090.165020.0004
Override
Cache load0.00200.3817250.0001
Sytem overhead
Fetch class attribute can translate value0.00060.121530.0002
Fetch class attribute name0.00130.245070.0002
XML
Image XML parsing0.00110.213730.0004
class_abstraction
Instantiating content class attribute0.00000.002980.0000
General
dbfile0.00110.2128230.0000
String conversion0.00000.002040.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
5content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
6content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
3content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 21
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs