eZ Community » Forums » Developer » Creating image alias in php ?

Creating image alias in php ?

Creating image alias in php ?

Friday 21 October 2011 7:21:52 pm - 20 replies

Hello everyone,

Does anybody knows how to create an image alias in php ?

I need to be able to execute the same thing "ezimage" operator is doing but in php.

Thank you in advance.

Friday 21 October 2011 7:47:27 pm

Hello H-Works,

You can use this class kernel/common/ezurloperator.php

in php to access the same function 'eZURLOperator::eZImage( )' in php.

Note: Image aliases are created on upload of image into ezimage datatype, they are not created on demand.

I hope this helps ...



Modified on Sunday 23 October 2011 7:43:37 pm by // Heath

Sunday 23 October 2011 9:40:44 pm

Hello Heath,

Thank you for this information.

If image aliases are generated on upload why the change of an image alias settings in image.ini is applied when clearing cache ?

For me - but i can be wrong - image aliases are created when calling "attribute_view_gui" on an "ezimage" attribute.

Monday 24 October 2011 1:39:01 am

It seems like we're looking for the similar thing:

As stated in this post, it seems that only small and reference aliases are generated upon object publishing.

All others are generated when you try to access the alias for the first time.

Monday 24 October 2011 2:29:01 am

Hello H-Works,

Your welcome. I'm happy to try to help.


Apologies if I misunderstood your question / needs.It seems I have misspoken slightly.
Yes image alias variations are normally created upon upload. But they are also created if they do not already exist.


I did not cover the related caches which must be cleared to make image alias settings changes available in served image alias variation images or adding new image alias settings. Image aliases variations are created if they do not already exist in the system or if their expiry cache has been cleared.

Note where Gaetano Giunta almosts validates my previous statements regarding image alias generation,

Related examples:

I think that image alias settings changes are recognized and available to the system if the related caches are cleared.

>> "If image aliases are generated on upload why the change of an image alias settings in image.ini is applied when clearing cache ?"

From what I see, image alias variations are created on demand if they do not already exist. Say after you add a new image alias settings, cleared related caches and reload the page for the first time.
This might help explain why you can easily add image aliases by clearing ini cache but can not change existing image aliases without clearing the image alias caches and or purging image alias cache.


If you want to change an existing image alias settings you must also clear ini and imagealias caches and/or purge the variations. Then reload the page for the first time, the image aliases which now no longer exist in the system will be regenerated. I'll expand on this further ...
I think clearing image alias and ini cache my be required to recognize your changes.


I think that when the content is loaded (in php) the ezimagealiashandler is called which in turn can generate image aliases which do not exist in the system yet,







The key here being invalidating the image alias caches and / or purging the image alias cache. Then changes are available in the served image aliases.

This seems to me that you can always add image aliases, but if you change an existing alias then the caches must be cleared.






>> "For me - but i can be wrong - image aliases are created when calling "attribute_view_gui" on an "ezimage" attribute."

I don't know what in the code makes you think image aliases are generated when calling attribute_view_gui, just read the template code called by that function, https://github.com/ezsystems/ezpublish/blob/master/design/standard/templates/content/datatype/view/ezimage.tpl


I did notice this somewhat related thread where zurgutt explains some hands on experiance clearing caches to invalidate image alias cache, so that each supsuquent request will regenerate the requested image and cache before serving the image alias to the user. http://share.ez.no/forums/developer/3.5-how-can-i-recreated-image-variations#comment42574

Also here is a hint about how image variation settings are processed causing regeneration, http://share.ez.no/forums/general/recreate-image-variations#comment29060

Another thread which highlights image variation changes being recognized and available after clearing caches, http://share.ez.no/forums/developer/how-can-i-regenerate-image-alias

Another thread which highlights image alias cache, http://share.ez.no/forums/developer/image-alias-deleted-after-clearing-cache


On this topic a recent improvement was made to make it simple to purge image aliases, not just invalidate them,




I hope this helps ...




Modified on Monday 24 October 2011 2:30:43 am by // Heath

Monday 24 October 2011 2:45:59 am

Yes image alias variations are normally created upon upload.

Heath, are you sure about that?

I have just tried it on eZP 2011.6, and it generates only "reference" and "small" aliases upon object publishing.

Modified on Monday 24 October 2011 2:46:32 am by Mavko Žmak - Žmale

Monday 24 October 2011 3:05:08 am

Hello Marko,

I base this on the following .. Where the datatype stores upload image content to attribute/datatype,



But your right, if you dig down further in the api you see it seems to only create the original image alias at this point in time.



To be fair I have honestly not tested these behaviors before posting. Only reading forum threads related and kernel api useage.

Though this code makes me lean to all image aliases except original are created on first request,






Modified on Monday 24 October 2011 3:06:06 am by // Heath

Monday 24 October 2011 3:16:09 am

Another note that might be relevant.


The ezimage operator [0] is not used for/with images stored in eZ Publish using the ezimage datatype or image alias variations. 


I guess the similar names can be confusing here ...


Rather ezimage operator is used to provide the path to the image in question in the current design (extension).


[0] http://doc.ez.no/eZ-Publish/Technical-manual/4.x/Reference/Template-operators/URLs/ezimage


The two types of files in the system are very different in practice and the usage is separated.





Monday 24 October 2011 5:17:05 am

This class method makes me thing you could write a PHP ezp cli script or cronjob which would fetch all content objects which contain the ezimage attribute/datatype, has image content and then invoke the attribute content 's ezimagealiashandler object imageAlias method which will generate the image alias image variations.


Example script

This got me inspired and I wrote this very basic example using the kernel api usage as a guide.

Note: I had source code formatting problems (a lot of them) trying to publish this simple example script on share.ez.no so I have posted it for long term safe keeping on ezpedia.org



I hope this helps ...




Modified on Monday 24 October 2011 5:43:13 am by // Heath

Monday 24 October 2011 8:51:03 am


You seem to be looking for the same thing as Marko through this post:


So maybe you should have a look at the latter, where some code is given. It may answer your needs

Monday 31 October 2011 5:42:58 am

Hello eZ Community!

Brookins Consulting is proud to announce the release of BC ImageAlias!


This packaged, complete extension provides a wide range of tools to use to generate and remove image alias image variation image files quickly, efficiently and effectively.

I suggest anyone trying to base a solution on the untested and now deprecated wiki article based source code examples to abandon this code as incomplete and ultimately not effective (enough) out of the box.

The bcimagealias extension has been heavily tested with the latest eZ Publish 4.5+ (2011.09 build) and works right out of the box.

We also would like to encourage anyone with questions or comments to publish these in the project forums.

Thanks again for your continued support! Enjoy generating and removing your image alias image variation image files!


Best wishes




Sunday 13 November 2011 11:18:24 am

Hello eZ Community,


Brookins Consulting is proud to announce we have migrated the bcimagealias extension from subversion to git.


The project is still available via http://projects.ez.no/bcimagealias


We hope this makes the extension that much more user friendly.


Best wishes




Sunday 13 November 2011 12:53:32 pm

Looks great but i can't add the event to the workflow.

I get this after publish :

Fatal error: Call to a member function validateHTTPInput() on a non-object in /www/ezpublish-4.2.0/kernel/workflow/edit.php on line 204

Any idea ?

Sunday 13 November 2011 1:03:03 pm

I still don't understand really how images aliases are generated.

What i thought is that after publication "default" aliases (those defined in settings/image.ini) were created but not "custom" aliases that were generated when calling "attribute_view_gui" on ezimage.

After few test i realize that some custom aliases are generated but others aren't. Even defined in the same image.ini.append.php file inside an extension.

For example i have an "extra-large" alias which is generated after publication and a "small-medium" alias which is never generated.

Does anybody knows the real behavior of ezp 4.x on this topic ?

Modified on Monday 14 November 2011 11:37:45 am by H-Works Agency

Monday 14 November 2011 2:20:42 am

Hello H-Works,

I'm very sorry. It seems there are still some issues to work out with this contribution's compatibility.

I belive there are still changes which we need to make. One I just noticed was that the workflow event is technically a few characters too long (among other important runtime issues we are also seeing.

I am working on addressing these concerns right away.

I will post again when I have addressed these concerns.

Thank you for your feedback. This really helps us ensure we deliver a complete solution.




Monday 14 November 2011 11:36:12 am

No problem Heath, its very nice of you to contribute with free extensions in the first place.

Would be great if your image generation workflow and cronjobs were integrated in ezp's kernel.

Monday 05 December 2011 1:01:42 pm

Hello H-Works,


We recently pushed a large number of changes to the bcimagealias extension project repository.

Our latest testing with 2011.09 shows this latest pushed version as a tested stable beta.


We are asking all users interested to please test again with the *much improved* latest version!




I hope this helps ...




Thursday 08 December 2011 7:31:40 am

Hello H-Works, Jerome, Marko and the rest of the eZ Community!


After a whole lot of development and testing I wanted to share some new developments tonight.


New features in BCImageAlias

I wanted to take a moment to share that we have recently pushed changes tonight which add new features to the bcimagealias extension which allows it to now generate content tree node object and all child node object image aliases via PHP, cli script and workflow event.

Previous versions of the extension were limited to generating by object-id (one object at a time). The new version allows for generation by node-id and optionally child node subtree(s) (many objects at one time).

This is the most common use case we see for new users of the extension and we are very happy to see these new features land in the project repository (among many other smaller improvements).

This means you can simply install the extension and very quickly generate all image aliases in the content tree(s)('Home', 'Media', 'Users' root node subtrees, in default install of ezwebin) directly, quickly and efficiently in one easy to use command line command.


We are not yet regularly reposting packages as the extension development continues at a more frequent pace. In the future after the next few waves of feature development we will establish a more regular release and package routine so users who don't use git just yet can always try the latest stable version.

As always you can still get the latest stable tested beta extension sources from github directly, https://github.com/brookinsconsulting/bcimagealias

And here is a copy of the latest version's changelog and the recent commit described above.




Feel free to ask more questions about bcimagealias, we would be happy to answer your questions!


I hope this helps ...




Sunday 11 December 2011 6:30:20 pm

Hello H-Works, Jerome, Marko and the rest of the eZ Community!


After a whole lot of development and testing I wanted to share some new developments today.

Today we have pushed a rather large set of improvements for bcimagealias extension to GitHub,


New features in BCImageAlias

Also it's worth mentioning we added support to the bcimagealias script and class for the parameters '--classes', '--attributes' and '--aliases'. You can see examples of how to use these parameters reviewing the doc/USAGE file, https://github.com/brookinsconsulting/bcimagealias/blob/master/doc/USAGE

We also added admin siteaccess content structure and popup class menu links. These links allow for you to use the same features as the command line script to create, regenerate and remove image alias image variation image files using two new module views 'create' and 'remove'. This was the initial focus for this iteration of development.

This makes it possible for any user with the required role policies to create, regenerate and remove image alias image variation image files using the existing content structure and popup class menus with the bcimagealias extension using the admin siteaccess without any complications.


You can review the changelog (as we have made many improvements to 0.0.23 version)



We hope this helps ...




Monday 12 December 2011 12:21:31 am

Hello Heath, everyone,

Thank you for that - Your content tree image generation feature sounds very handy.

I am gonna try it and report !

If you need a french translation for this extension feel free to ask.



Monday 12 December 2011 12:31:28 am

Hello Martin,

Your very welcome. We are here to help people reach their goals simply and effectively.

We look forward to your testing feedback and report results happy.gif Emoticon

We would welcome your contribution of a french translation for the extension via GitHub pull request. The translation strings are not many so it would take you very little time to complete the translation of the strings in general.


Best wishes





You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from