Forums / General / Downloading a scaled version of an image

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>

eZ debug

Timing: Jan 18 2025 11:34:48
Script start
Timing: Jan 18 2025 11:34:48
Module start 'content'
Timing: Jan 18 2025 11:34:48
Module end 'content'
Timing: Jan 18 2025 11:34:48
Script end

Main resources:

Total runtime0.8211 sec
Peak memory usage4,096.0000 KB
Database Queries194

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0071 587.8203180.8203
Module start 'content' 0.00710.6631 768.6406550.6484
Module end 'content' 0.67030.1507 1,319.2891336.7656
Script end 0.8210  1,656.0547 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00440.5336210.0002
Check MTime0.00180.2156210.0001
Mysql Total
Database connection0.00090.113410.0009
Mysqli_queries0.746790.93481940.0038
Looping result0.00260.31791920.0000
Template Total0.787395.920.3937
Template load0.00190.234620.0010
Template processing0.785495.647420.3927
Template load and register function0.00020.028410.0002
states
state_id_array0.00140.169010.0014
state_identifier_array0.00090.113420.0005
Override
Cache load0.00160.1975240.0001
Sytem overhead
Fetch class attribute can translate value0.00260.311130.0009
Fetch class attribute name0.00190.235040.0005
XML
Image XML parsing0.00100.124430.0003
class_abstraction
Instantiating content class attribute0.00000.001340.0000
General
dbfile0.00240.2871280.0001
String conversion0.00000.000930.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 18
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs