We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 50574
    • 70 Posts
    Hello

    I'd like to utilise a little bit of script I found on Stackoverflow for PHP GD that basically recreates the Photoshop multiply effect with web images.
    <?php 
    $filter_r=216;
    $filter_g=0;
    $filter_b=26;
    $suffixe="_red";
    $path=YOURPATHFILE;
    
    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);
    }
    ?>

    I however, need a few elements of this to be dynamic. The RGB filter vars will change depending on a BG colour chosen by the user and the path will also change for each image. Is there any info on how I can manipulate this to include dynamic content such as including TV names etc?

    The images are also currently populated using pThumb, if that makes any difference.

    Thanks in advance
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      You can use GET, system settings, TVs, cookie or session values for variables. I'd be inclined to make this a snippet so that all of the MODX APIs and what-have-you are available. For example, $modx->getOption() can get more than just settings or properties. http://bobsguides.com/blog.html/2014/08/14/understanding-the-modx-getoption%28%29-method/
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 50574
        • 70 Posts
        Thank you Susan. I'll take a look and report back how I get on.