How do I work with images from an extension?

Author Message

Daniel Staver

Tuesday 27 June 2006 4:24:03 am

I have a really slow thumbnail page that I'm trying to speed up by making an extension for listing the thumbnails.

I want to make some SQL to list the images, find a particular image variation and display the thumbnail linked to the URL alias of the image.

Problem is, I can't find documentation on how to get a particular image variation from the image XML stored in the database. I assume there must be some functions that already handle this. I also want to re-generate the thumbnail if there's been any updates to the image object or the thumbnail doesn't already exist.

I'm not sure if this will actually be any faster than just doing it from a template, but I'd still like to learn how to do it just as an excercise.

Here's the page:
http://daniel.staver.no/home/gallery/buildings/chimney_v

The thumbnails on the left side account for about 85% of the processing time. The page takes about 1.7 seconds to generate even with compiling and viewcaching switched on. I'd really like this page to display much faster.

Here's the code I'm using:

{def $parent=$node.parent}
<h3>Images in {$parent.name}</h3>
{def
	$images = fetch( content, list, hash(
		parent_node_id, $parent.node_id,
		sort_by, array( published, false() )
		
	))
}
{cleanup_whitespace}
	{section loop=$images}
		<div class="image">
			{if $:item.node_id|eq($node.node_id)}
				<img src={$:item.data_map.image.content.squarethumb_selected.url|ezurl} alt="{$:item.name}" /> 
			{else}
				<a href={$:item.url_alias|ezurl()}><img src={$:item.data_map.image.content.squarethumb.url|ezurl} alt="{$:item.name}" /></a>
			{/if}
		</div>
	{/section}
{/cleanup_whitespace}

Any suggestions? I don't want to use a cache block for this as I need to highlight the selected image which means the menu will change on every page.

Daniel Staver
http://daniel.staver.no

Ɓukasz Serwatka

Tuesday 27 June 2006 6:01:52 am

Hei,

You can do like:

include_once( 'kernel/classes/ezcontentobjecttreenode.php' );
 
// {def $node=fetch( 'content', 'node', hash( 'node_id', 82 ) )}
$node =& eZContentObjectTreeNode::fetch( 82 );
 
// {$node.object.data_map}
$object =& $node->object();
$dataMap =& $object->dataMap();
 
// {$node.object.data_map.image.content[original].full_path}
$image =& $dataMap['image']->content();
$aliasList =& $image->aliasList();
$fullPath = $aliasList['original']['full_path'];

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Daniel Staver

Tuesday 27 June 2006 8:07:49 am

Thanks! I'll try that. Will I notice any efficiency gains from doing it with this code instead? My first impressions is that it goes through exactly the same steps as what I do in my template...

Any ideas why my template is so slow in the first place? I'm just listing a bunch of pre-generated thumbnails. It should be possible to do something like that almost instantly.

Daniel Staver
http://daniel.staver.no

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