MultiplyImages ViewHelper

Funktion

Es wird eine Farbe definiert (in diesem Fall rot), die dann Pixel per Pixel ins Bild multipliziert wird.

Installation

h2template/Classes/ViewHelpers/MultiplyImageViewHelper.php

usage:

<f:image src="{m:multiplyImage(path:'image')}" alt=""/>

Known Issues

Momentan nur von jpg zu png möglich

Code

<?php
namespace HOCHZWEI\H2template\ViewHelpers;
/**
 *
 *
 * @package HOCHZWEI
 * @subpackage H2template
 * @version
 */
class MultiplyImageViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {


    /**
     *
     *
     * @param string $path
     * @return string
     */
    public function render($path) {
        $filter_r=227;
        $filter_g=4;
        $filter_b=15;
        $suffixe="_red";

        if(is_file($path)){
            $image=@imagecreatefromjpeg($path);
            $new_path=substr($path,0,strlen($path)-4).$suffixe.".png";

            $imagex = imagesx($image);
            $imagey = imagesy($image);
            for ($x = 0; $x <$imagex; ++$x) {
                for ($y = 0; $y <$imagey; ++$y) {
                    $rgb = imagecolorat($image, $x, $y);
                    $TabColors=imagecolorsforindex ( $image , $rgb );
                    $color_r=floor($TabColors['red']*$filter_r/255);
                    $color_g=floor($TabColors['green']*$filter_g/255);
                    $color_b=floor($TabColors['blue']*$filter_b/255);
                    $newcol = imagecolorallocate($image, $color_r,$color_g,$color_b);
                    imagesetpixel($image, $x, $y, $newcol);
                }
            }

            imagepng($image,$new_path);
        }
        return $new_path;
    }
}

?>