PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, October 10, 2022

[FIXED] How to have a function like color overlay with color blend mode without using ImageMagick

 October 10, 2022     gd, image-processing, php     No comments   

Issue

I want to manipulate an image using php only with the result like the color blend mode in photoshop. I hope you can help me.

I have this code but it returns an image that is like a screen blend mode.

<?php
$img="text.png";
$to="";
$bool="";
$imres=$img;

if(isset($_POST['submit'])){
    $im = imagecreatefrompng('text.png');
    // $from=$_POST['oldhex'];

    $to=$_POST['newhex'];
    //conversion of hex to rgb values

    // Get width and height
    // $w = imagesx($im); 
    // $h = imagesy($im);
    // $im= imagecreatetruecolor($w,$h);



    ![enter image description here][1]$r = hexdec(substr($to, 0, 2));
    $g = hexdec(substr($to, 2, 2));
    $b = hexdec(substr($to, 4, 2));
    /* R, G, B, so 0, 255, 0 is green */

    if($im && imagefilter($im, IMG_FILTER_COLORIZE, $r, $g, $b,30)&& imagealphablending($im, true)){// echo 'Image successfully shaded';


        imagepng($im, '5.png');
        $bool="true";
        $imres="5.png";
    }
    else{
        echo 'shading failed.';
    }
}
?>

This is the input image

enter image description here

This is the image that I get...

failed image

This is the image that i want to haveenter image description here


Solution

I have had a try at this and got somethimng fairly similar to what you want - maybe it will give you some ideas for further experimentation. Basically I create another image the same size as yours and fill it with a colour wash and transparency and then blend them.

#!/usr/bin/php
<?php

    $im = imagecreatefrompng('text.png');

    $to='FFCC33';
    //conversion of hex to rgb values

    $r = hexdec(substr($to, 0, 2));
    $g = hexdec(substr($to, 2, 2));
    $b = hexdec(substr($to, 4, 2));

    $wash=imagecreatetruecolor(225,225);
    $col = imagecolorallocatealpha($wash,$r,$g,$b,70);
    imagefill($wash,0,0,$col);

    imagelayereffect($im,IMG_EFFECT_ALPHABLEND);
    imagecopy($im,$wash,0,0,0,0,225,225);
    imagepng($im,'5.png');
?>


Answered By - Mark Setchell
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing