TYPO3 Flow Base DistributionPackagesApplications

Bug #37464

ImageViewhelper with params

Added by Mike Streibl about 3 years ago. Updated over 1 year ago.

Status:New Start date:2012-05-24
Priority:Could have Due date:
Assigned To:- % Done:

0%

Category:-
Target version:-
Has patch:No Tags:

Description

<?php

/*                                                                        *
 * This script belongs to the FLOW3 package "Fluid".                      *
 *                                                                        *
 * It is free software; you can redistribute it and/or modify it under    *
 * the terms of the GNU Lesser General Public License as published by the *
 * Free Software Foundation, either version 3 of the License, or (at your *
 * option) any later version.                                             *
 *                                                                        *
 * This script is distributed in the hope that it will be useful, but     *
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser       *
 * General Public License for more details.                               *
 *                                                                        *
 * You should have received a copy of the GNU Lesser General Public       *
 * License along with the script.                                         *
 * If not, see http://www.gnu.org/licenses/lgpl.html                      *
 *                                                                        *
 * The TYPO3 project - inspiring people to share!                         *
 *                                                                        */

class Tx_DlExtlib_ViewHelpers_ImageViewHelper extends Tx_Fluid_ViewHelpers_ImageViewHelper {
    /**
     * Resizes a given image (if required) and renders the respective img tag
     * @see http://typo3.org/documentation/document-library/references/doc_core_tsref/4.2.0/view/1/5/#id4164427
     *
     * @param string $src
     * @param string $width width of the image. This can be a numeric value representing the fixed width of the image in pixels. But you can also perform simple calculations by adding "m" or "c" to the value. See imgResource.width for possible options.
     * @param string $height height of the image. This can be a numeric value representing the fixed height of the image in pixels. But you can also perform simple calculations by adding "m" or "c" to the value. See imgResource.width for possible options.
     * @param integer $minWidth minimum width of the image
     * @param integer $minHeight minimum height of the image
     * @param integer $maxWidth maximum width of the image
     * @param integer $maxHeight maximum height of the image
     * @param string $params
     *
     * @return string rendered tag.
     * @author Sebastian Böttger <sboettger@cross-content.com>
     * @author Bastian Waidelich <bastian@typo3.org>
     * @author Mike Streibl <m.streibl@die-lobby.de>
     */
    public function render($src, $width = NULL, $height = NULL, $minWidth = NULL, $minHeight = NULL, $maxWidth = NULL, $maxHeight = NULL, $params = NULL) {

        $setup = array(
            'width' => $width,
            'height' => $height,
            'minW' => $minWidth,
            'minH' => $minHeight,
            'maxW' => $maxWidth,
            'maxH' => $maxHeight,
            'params' => $params
        );
        $imageInfo = $this->contentObject->getImgResource($src, $setup);
        $imageInfo[3] = t3lib_div::png_to_gif_by_imagemagick($imageInfo[3]);
        $imageSource = $GLOBALS['TSFE']->absRefPrefix . t3lib_div::rawUrlEncodeFP($imageInfo[3]);

        return parent::render($imageSource, $width, $height, $minWidth, $minHeight, $maxWidth, $maxHeight );

    }

}

?>

Example:

{namespace vh=Tx_DlExtlib_ViewHelpers}

<vh:image src="uploads/pics/{user.profileImage}" alt="{user.lastName}" height="80c" width="65" params="-colorspace GRAY"/>

History

#1 Updated by Fedir RYKHTIK almost 2 years ago

+1 It's very important to have the possibility to send additional params to adjust the colorspace, to make advanced cropping / resizing. The patch should be a bit updated to be compatible with current core.

Also available in: Atom PDF