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.