Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8665549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:30:24+00:00 2026-06-12T17:30:24+00:00

I need to create a command that mimics Adobe Photoshop’s Color blend mode in

  • 0

I need to create a command that mimics Adobe Photoshop’s “Color” blend mode in ImageMagick in order to tint an image. In order to do this, I’m trying to compose the original image and another image that consists of a full color layer, at 35% opacity. This should blend with the original image and create a color tinted result image.

This is the expected result:
the expected result

The “Color” blend mode is being defined, on the Adobe site, like this: “Creates a result color with the luminance of the base color and the hue and saturation of the blend color. This preserves the gray levels in the image and is useful for coloring monochrome images and for tinting color images.”

There is a compose method defined into ImageMagick that seems to do the same thing (Luminize), but the results are not by far what is expected.

What seems to provide the closest result in Imagemagick is the default blend compose method, used like this:

convert image.jpg color_layer.png -compose blend -composite result.jpg

I also tried creating an image that would contain the luminosity of the first image and the hue and saturation of the second using the -fx operator, but the result was again nowhere near what I needed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T17:30:25+00:00Added an answer on June 12, 2026 at 5:30 pm

    Based on Castles valuable answer, I tried to find the best solution of doing this in PHP. The implementation he cited has two major flaws: one that it doesn’t take account of the opacity, if any and the second that is very slow and resource consuming. Processing a 500×500 pixels image in PHP would take about 15 seconds in which Apache would hold the processor up to 95%.

    The fastest and least resources consuming I found was actually doing it in HTML5 by using canvas to process the image. The results are amazing and the image is being processed on the spot.

    I will post below the final chunks of code, one for PHP and one for HTML. If you need to use this serverside, you can copy-paste the HTML code in Node.js and NodeCanvas: https://github.com/LearnBoost/node-canvas

    PHP (with opacity):

    <?php
    
    function Lum($colour) {
        return ($colour['r'] * 0.3) + ($colour['g'] * 0.59) + ($colour['b'] * 0.11);
    }
    
    function ClipColour($colour) {
        $result     = $colour;
        $luminance  = Lum($colour);
    
        $cMin = min($colour['r'], $colour['g'], $colour['b']);
        $cMax = max($colour['r'], $colour['g'], $colour['b']);
    
        if ($cMin < 0.0) {
            $result['r'] = $luminance + ((($colour['r'] - $luminance) * $luminance) / ($luminance - $cMin));
            $result['g'] = $luminance + ((($colour['g'] - $luminance) * $luminance) / ($luminance - $cMin));
            $result['b'] = $luminance + ((($colour['b'] - $luminance) * $luminance) / ($luminance - $cMin));
        } 
    
        if ($cMax > 255) {
            $result['r'] = $luminance + ((($colour['r'] - $luminance) * (255 - $luminance)) / ($cMax - $luminance));
            $result['g'] = $luminance + ((($colour['g'] - $luminance) * (255 - $luminance)) / ($cMax - $luminance));
            $result['b'] = $luminance + ((($colour['b'] - $luminance) * (255 - $luminance)) / ($cMax - $luminance));
        }
    
        return $result;
    }
    
    function SetLum($colour, $luminance) {
    
        $result = array();
    
        $diff =   $luminance - Lum($colour);
    
        $result['r'] = $colour['r'] + $diff;
        $result['g'] = $colour['g'] + $diff;
        $result['b'] = $colour['b'] + $diff;
    
        return ClipColour($result);
    
    } 
    
    function normalizeColor( $color ) {
        $color['r'] = $color['r'] / 255;
        $color['g'] = $color['g'] / 255;
        $color['b'] = $color['b'] / 255;
    
        return $color;
    }
    
    function denormalizeColor( $color ) {
        $color['r'] = round($color['r'] * 255);
        $color['g'] = round($color['g'] * 255);
        $color['b'] = round($color['b'] * 255);
    
        return $color;
    }
    
    $overlay_color = array('r'=>180,'g'=>22,'b'=>1, 'a' => 0.35);
    
    $img = new Imagick();
    
    if( !isset($_GET['case']) ) {
        $_GET['case'] = '';
    }
    
    //unmodified version
    $original   = new Imagick('girl.jpg');
    
    //photoshop image to compare
    $ps = new Imagick('original.jpg');
    
    $img->addImage($original);
    $it = $original->getPixelIterator();
    
    foreach( $it as $row => $pixels ) {
        foreach ( $pixels as $column => $pixel ) {
            $rgbIni = $pixel->getColor();
    
            $rgb = SetLum($overlay_color, Lum($rgbIni));
             $overlay_color     = normalizeColor($overlay_color);
                $rgb        = normalizeColor($rgb);
    
                $rgbIni         = normalizeColor($rgbIni);
    
            $rgb['r'] = ((1 - $overlay_color['a']) * $rgbIni['r']) + ($overlay_color['a'] * $rgb['r']);
            $rgb['g'] = ((1 - $overlay_color['a']) * $rgbIni['g']) + ($overlay_color['a'] * $rgb['g']);
            $rgb['b'] = ((1 - $overlay_color['a']) * $rgbIni['b']) + ($overlay_color['a'] * $rgb['b']);
    
            $test           = denormalizeColor($test);
            $rgb            = denormalizeColor($rgb);
            $overlay_color  = denormalizeColor($overlay_color);
    
            $pixel->setColor('rgb('.round($rgb['r']).','. round($rgb['g']).','.round($rgb['b']).')');
    
        }
    
        $it->syncIterator();
    }
    
    //add modified version
    $img->addImage($original);
    $img->addImage($ps);
    
    $img->resetIterator();
    $combined = $img->appendImages(true); //stack images
    
    header('content-type: image/jpeg');
    
    $combined->setImageFormat("jpeg");
    
    echo $combined;
    
    ?>
    

    HTML:

    <!DOCTYPE html>
        <html lang="en">
        <head>
        <meta charset="UTF-8" />
        <script>
            var RGBA = function(r, g, b, a) {
                this.R = r || 0;
                this.G = g || 0;
                this.B = b || 0;
                this.A = a || 0.5;
            }
    
            function SetLum(initialColor, pixelColor) {
    
                var initalColorLuminance = initialColor.R * 0.3 + initialColor.G * 0.59 + initialColor.B * 0.11;
                var pixelColorLuminance = pixelColor.R * 0.3 + pixelColor.G * 0.59 + pixelColor.B * 0.11;
    
                var diff = pixelColorLuminance - initalColorLuminance;
    
                var response = new Array;
                   response[0] = initialColor.R + diff;
                   response[1] = initialColor.G + diff;
                   response[2] = initialColor.B + diff;
    
                //console.log(response[0]);
    
                return ClipColour(response);
    
            }
    
            function alphaComposite(mv, ov, a) {
                return (mv * a) + (ov * (1 - a));
            }
    
            function ClipColour(color) { //function to prevent underexposure or overexposure on some pixels
    
                var result     = color;
                var luminance  = color[0] * 0.3 + color[1] * 0.59 + color[1] * 0.11;
    
                var cMin = Math.min(color[0], color[1], color[2]);
                var cMax = Math.max(color[0], color[1], color[2]);
    
                if (cMin < 0.0) {
                    color[0] = luminance + (((color[0] - luminance) * luminance) / (luminance - cMin));
                    color[1] = luminance + (((color[1] - luminance) * luminance) / (luminance - cMin));
                    color[2] = luminance + (((color[2] - luminance) * luminance) / (luminance - cMin));
                } 
    
                if (cMax > 255) {
                    color[0] = luminance + (((color[0] - luminance) * (255 - luminance)) / (cMax - luminance));
                    color[1] = luminance + (((color[1] - luminance) * (255 - luminance)) / (cMax - luminance));
                    color[2] = luminance + (((color[2] - luminance) * (255 - luminance)) / (cMax - luminance));
                }
    
                return color;
            }
    
            function processImage(image, targetColour) {
                var canvas = document.createElement('canvas');
                    c = canvas.getContext('2d');
    
                canvas.width = image.width;
                canvas.height = image.height;
    
                // Draw the building on the original canvas
                c.drawImage(image, 0, 0, canvas.width, canvas.height);
    
                // There's a (much) faster way to cycle through all the pixels using typed arrays, 
                // but I'm playing it safe so that the example works in all browsers.
                var imageData = c.getImageData(0, 0, canvas.width, canvas.height),
                    imageDataPixels = imageData.data;
    
                for (var i = 0, len = imageDataPixels.length; i < len; i += 4) {
                    var pixelColor = new RGBA(imageDataPixels[i], imageDataPixels[i+1], imageDataPixels[i+2], 1);
                    var test = SetLum(targetColour, pixelColor);
    
                    var r    = Math.round(test[0]);
                    var g    = Math.round(test[1]);
                    var b    = Math.round(test[2]);
    
                    imageDataPixels[i] = alphaComposite(r, imageDataPixels[i], targetColour.A);
                    imageDataPixels[i + 1] = alphaComposite(g, imageDataPixels[i + 1], targetColour.A);
                    imageDataPixels[i + 2] = alphaComposite(b, imageDataPixels[i + 2], targetColour.A);
                }
    
                c.putImageData(imageData, 0, 0);
    
                return canvas;
            }
    
            document.addEventListener('DOMContentLoaded', function() {
                var image = new Image(),
                    processImageFile = null;
    
                image.src = "girl.jpg";
    
                image.addEventListener('load', function() {
                    var canvas = document.getElementById('canvas'),
                        c = canvas.getContext('2d'),
                        imageRGBA = new RGBA(180, 22, 1, 0.35);
    
                    canvas.width = image.width;
                    canvas.height = image.height;
    
                    c.drawImage(image, 0, 0);
    
                    processImageFile = processImage(image, imageRGBA);
                    c.drawImage(processImageFile, 0, 0);
                });
            });
        </script>
    </head>
    <body>
    
        <img src="girl.jpg" />
        <br />
    
        <canvas id="canvas"></canvas>
    
        <br />
        <img src="original.jpg" />
    </body>
    

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, so I need to create a command that lists the 100 most frequent
I need to create a batch script that will run a reboot command but
I need to create a Java command line to that will be invoked remotely
I need to create a layered PSD file with ImageMagick or any other command-line
Essentially, I need to parse the response string of the CHAT CREATE command with
I need to create an AS/400 command. This command has a parameter with decimal
I need to create a .exe file that opens an .html document with the
I need to create a script that backups a couple of files on a
I am working with Excel 2010. I need to create a macro, that after
I'd need to create simple patches from git repository that can be applied with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.