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.

eZ debug

Timing: Jan 31 2025 00:39:14
Script start
Timing: Jan 31 2025 00:39:14
Module start 'layout'
Timing: Jan 31 2025 00:39:14
Module start 'content'
Timing: Jan 31 2025 00:39:15
Module end 'content'
Timing: Jan 31 2025 00:39:15
Script end

Main resources:

Total runtime0.0242 sec
Peak memory usage4,096.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0057 589.3984151.2266
Module start 'layout' 0.00570.0036 740.6250220.7188
Module start 'content' 0.00930.0134 961.34381,001.9609
Module end 'content' 0.02260.0016 1,963.304733.9922
Script end 0.0242  1,997.2969 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002811.4149140.0002
Check MTime0.00124.8802140.0001
Mysql Total
Database connection0.00114.620310.0011
Mysqli_queries0.00249.702230.0008
Looping result0.00000.049210.0000
Template Total0.00114.610.0011
Template load0.00093.612410.0009
Template processing0.00020.921310.0002
Override
Cache load0.00062.543410.0006
General
dbfile0.00031.170380.0000
String conversion0.00000.030540.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_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