Downloading a scaled version of an image

Author Message

Holger Marx

Wednesday 20 August 2008 9:01:50 am

I want to offer downloads of several sizes of one and the image to the visitor of my website.

The image object is an instance of the image class.
For downloading the original image I use "content/download/123/123/filename.jpg". Is it possible to use the download-view in connection with an image alias such as "medium", "small" or "large"?

If download-view can't be used, is there any way to realize my idea (except of using the path to var-directory)?

André R.

Wednesday 20 August 2008 9:09:10 am

It's not supported at the moment:
http://issues.ez.no/IssueView.php?Id=12067&activeItem=66

The only choice I can think of is to fork content/download code to your own module extension and modify it to support additional parameter for image alias.

If you do find a solution, it would be interesting to get the patch / code attached to the above issue, so we can implement it.

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

Holger Marx

Friday 17 October 2008 6:42:12 am

My suggestion to realize the download of a scaled image is the following:

<b>1. My download link looks like this .../content/download/<contentobject_id>/<node_id>/<filename_of_the_relevant_image_alias></b>

The filename of the relevant image alias could be for example: my_image_small.jpg

<b>2. Creating a new module with a customized binaryhandler (myfilepassthroughhandler.php)</b>
The determining function which has to be tuned is handleFileDownload. In this function the path to the scaled image has to be detected.
This is the way I detect the path (replace the line "$fileName = $fileInfo['filepath'];"):

if( $contentObjectAttribute->DataTypeString == 'ezimage'){
    $myPathInfoList = array_reverse( split( '/', $_SERVER['PATH_INFO'] ) );

    $myObjectDataArray = $contentObjectAttribute->Content->ContentObjectAttributeData;

    $myBasename = $myObjectDataArray['DataTypeCustom']['alias_list']['original']['basename'];
    $myFilename = $myPathInfoList[0];

    $myPostfixList = split( $myBasename, $myFilename );

    $myAlias = splitFilename( $myPostfixList[1] );
    $myFullPath = $myObjectDataArray['DataTypeCustom']['alias_list'][$myAlias]['full_path'];

    $fileName = $myFullPath;
}
else {
    $fileName = $fileInfo['filepath'];
}

The function splitFilename looks like this:

function splitFilename( $filename )
{
    $pos = strrpos($filename, '.');
    if ($pos === false)
    { // dot is not found in the filename
        return 0; // no extension
    }
    else
    {
        $basename = substr($filename, 0, $pos);
        $extension = substr($filename, $pos+1);
        return ltrim( $basename, '_');
    }
}

<b>3. Access to var-directory has to be limited via htaccess-file</b>

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 16:04:13
Script start
Timing: Jan 18 2025 16:04:13
Module start 'layout'
Timing: Jan 18 2025 16:04:13
Module start 'content'
Timing: Jan 18 2025 16:04:14
Module end 'content'
Timing: Jan 18 2025 16:04:14
Script end

Main resources:

Total runtime0.5916 sec
Peak memory usage4,096.0000 KB
Database Queries57

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0053 588.0391152.6406
Module start 'layout' 0.00540.0028 740.679739.4609
Module start 'content' 0.00810.5822 780.1406545.5547
Module end 'content' 0.59030.0013 1,325.695312.1406
Script end 0.5915  1,337.8359 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00330.5495160.0002
Check MTime0.00130.2199160.0001
Mysql Total
Database connection0.00080.142710.0008
Mysqli_queries0.550092.9670570.0096
Looping result0.00050.0812550.0000
Template Total0.564495.420.2822
Template load0.00200.341420.0010
Template processing0.562495.061120.2812
Template load and register function0.00010.019110.0001
states
state_id_array0.00080.140310.0008
state_identifier_array0.00070.111020.0003
Override
Cache load0.00170.2870240.0001
Sytem overhead
Fetch class attribute can translate value0.00070.120220.0004
Fetch class attribute name0.00080.132740.0002
XML
Image XML parsing0.00060.096220.0003
class_abstraction
Instantiating content class attribute0.00000.001240.0000
General
dbfile0.00070.1154170.0000
String conversion0.00000.001540.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
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
7content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
2content/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: 18
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs