Skip to content

CMYK Conversion #122

@kyndder

Description

@kyndder

First of all, congratulations for this great tool!

Because of a very specific case, I needed to convert about 6000 colors using its CIELab values, to its corresponding CMYK values and, with this values, feed a color library of a specific application used by print purposes.

As that library is used only for color representation on screen and, being CMYK the only color space interpreted by the application, pastel helped me a lot to achieve my need.

Using pastel + a simple script I made to help me on the bulk conversion, in only one day I was able to make a job that could had took many days, using any other workaround.

Here's the script;

#!/bin/bash

c=""
m=""
y=""
k=""
re='^[0-9]+$'
r=""
g=""
b=""

read r g b
biggest=$r
if [ $g -gt $biggest ]
then
	biggest=$g
	
	if [ $b -gt $biggest ]
	then
		biggest=$b
	fi
fi

calc()
{
key=`echo "scale=4;(1-($biggest/255))"|bc -l` 
cyan=`echo "scale=4;((1-($r/255)-$key)/(1-$key))"|bc -l`
magenta=`echo "scale=4;((1-($g/255)-$key)/(1-$key))"|bc -l`
yellow=`echo "scale=4;((1-($b/255)-$key)/(1-$key))"|bc -l`

k=`echo "($key*100)" | bc -l | awk '{printf "%.0f\n", $0}'`
c=`echo "($cyan*100)" | bc -l | awk '{printf "%.0f\n", $0}'`
m=`echo "($magenta*100)" | bc -l | awk '{printf "%.0f\n", $0}'`
y=`echo "($yellow*100)" | bc -l | awk '{printf "%.0f\n", $0}'`
} 2> /dev/null

calc

if ! [[ $c =~ $re ]] ; then
   c=0
fi

if ! [[ $m =~ $re ]] ; then
   m=0
fi

if ! [[ $y =~ $re ]] ; then
   y=0
fi

output="cmyk($c $m $y $k)"

if command -v pastel > /dev/null 2>&1 ; then
	fg="$(pastel textcolor "rgb($r,$g,$b)")"
	pastel paint "$fg" --on "rgb($r,$g,$b)" "$output"
else
	echo "$output"
fi

And here, a sample output;
rgb2cmyk

It would be great if some day we have native CMYK convertion in pastel.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions