CMYK Formula Editor

Edit images with math: type a formula for the cyan, magenta, yellow and black ink of every pixel.

CMYK Formula Editor is a free online tool to edit images using math formulas on the CMYK inks. Printers make every color with four inks: cyan, magenta, yellow and black (K). Here each pixel of your image is split into these four inks, from 0% to 100%, and you write a formula for the new amount of each ink, plus the transparency (alpha).

Thinking in inks makes some edits very simple: k * 0.5 lifts the shadows without washing out their colors, k = 0 shows the image without the black plate, y + 15 adds yellow ink everywhere, and setting three inks to 0 shows a single color separation. With the position of the pixel, the formulas can even turn the image into halftone dots, like a printed magazine.

The formulas are evaluated by your graphics card (with WebGL2), so the image updates while you type, even for large photos. Everything runs in your browser: your image is never uploaded to a server. You can also edit images with formulas for the red, green and blue channels, or for the hue, saturation and lightness.

Drop your image here
You can also paste an image with Ctrl+V.

Examples

Click on any example to apply its formulas to your image (or to the sample image, if you haven't opened one), and edit them.

Original image
The sample image, before applying any formula.
Lift the shadows
Half of the black ink is removed, so the dark areas become lighter but keep their colors, without the gray look of a brightness filter.
Cc
Mm
Yy
Kk * 0.5
Aa
Without the black ink
Only the cyan, magenta and yellow inks are printed. The shadows turn into strong, flat colors, like a print with the black plate missing.
Cc
Mm
Yy
K0
Aa
Cyan plate
Only the cyan ink: the plate that prints the cyan parts of the image.
Cc
M0
Y0
K0
Aa
Magenta plate
Only the magenta ink. The skin and the lips need a lot of it.
C0
Mm
Y0
K0
Aa
Yellow plate
Only the yellow ink, which is in all the warm colors.
C0
M0
Yy
K0
Aa
Black plate
Only the black ink, which carries the darkness of the image.
C0
M0
Y0
Kk
Aa
Add yellow and magenta ink
Adds 15% of yellow and 6% of magenta ink to every pixel, which gives a warm, golden tone, even to the white areas.
Cc
Mm + 6
Yy + 15
Kk
Aa
Old faded print
Every ink is weaker, and a little yellow is added everywhere, like an old magazine page on yellowed paper.
Cc * 0.55
Mm * 0.6
Yy * 0.6 + 12
Kk * 0.7
Aa
Two inks: magenta and black
All the color goes into the magenta ink, and the black ink is kept, like a print made with only two inks.
C0
Mmax(c, m, y)
Y0
Kk
Aa
Comic book colors
Each ink is rounded to 0%, 50% or 100%, and only the darkest shadows get black ink, which gives bright, flat colors with solid black shadows.
Cround(c / 50) * 50
Mround(m / 50) * 50
Yround(y / 50) * 50
Kk > 75 ? 100 : 0
Aa
CMYK halftone
Each ink becomes a grid of dots, turned by a different angle, like a printed magazine seen through a magnifying glass. Change 250 to make the dots bigger or smaller.
C(cos(250 * (px * 0.966 + py * 0.259) / width) + cos(250 * (py * 0.966 - px * 0.259) / width)) / 2 > 1 - c / 50 ? 100 : 0
M(cos(250 * (px * 0.259 + py * 0.966) / width) + cos(250 * (py * 0.259 - px * 0.966) / width)) / 2 > 1 - m / 50 ? 100 : 0
Y(cos(250 * px / width) + cos(250 * py / width)) / 2 > 1 - y / 50 ? 100 : 0
K(cos(177 * (px + py) / width) + cos(177 * (py - px) / width)) / 2 > 1 - k / 50 ? 100 : 0
Aa
Newspaper halftone
Only black dots, larger where the image is darker, like a photo printed in a newspaper.
C0
M0
Y0
K(cos(177 * (px + py) / width) + cos(177 * (py - px) / width)) / 2 > (0.299 * r + 0.587 * g + 0.114 * b) / 127.5 - 1 ? 100 : 0
Aa

How to edit an image with CMYK formulas?

  1. Upload your image - Drop a JPG, PNG or WebP image in the box above, or paste an image with Ctrl+V, or click "Try it with a sample image".
  2. Type the formulas - One for the new amount of each ink: cyan (C), magenta (M), yellow (Y) and black (K), from 0 to 100, and one for the new alpha (A). The formulas can use the original inks of the pixel, like k * 0.5 or y + 10. The image updates while you type, and errors are shown below the formula.
  3. Start from an example (optional) - Click on one of the examples above to load its formulas, and change them.
  4. Choose what happens to values outside the range - "Clamp" (recommended) keeps every ink between 0% and 100%. "Bounce" and "remainder" make bands of colors.
  5. Download the image - Click "Download image" to save the result as a PNG image, with its transparency.

Documentation

What is CMYK?

CMYK is the way printers make colors: they put dots of four inks on white paper. Each ink absorbs part of the light, so the more ink, the darker the color (screens do the opposite, adding red, green and blue light).

  • Cyan (C) absorbs red light, magenta (M) absorbs green light and yellow (Y) absorbs blue light. Magenta and yellow together make red, cyan and yellow make green, and cyan and magenta make blue.
  • Black (K, for "key") makes the dark parts. In theory the three colored inks together make black, but in practice they make a muddy brown and use a lot of ink, so a black ink is added.
  • Each ink goes from 0 (no ink, the white paper shows) to 100 (the paper is fully covered).

This tool converts each pixel with the simple formulas used by most websites: the black ink is the darkness of the strongest of the red, green and blue channels, k = 100 - max(r, g, b) / 2.55, and the other inks make the rest of the color. So a pure black pixel has only black ink, and a pure color like red has no black at all. The result is converted back to red, green and blue to be shown on the screen:

  • red = 255 × (1 - C / 100) × (1 - K / 100)
  • green = 255 × (1 - M / 100) × (1 - K / 100)
  • blue = 255 × (1 - Y / 100) × (1 - K / 100)

Color separations (plates)

A printing press prints the four inks one after the other, each with its own plate. Setting three inks to 0 shows what a single plate prints, like the "Cyan plate" and "Black plate" examples above. A separation shown this way is a preview made with the simple formulas above, not the exact plates of a professional printer, which depend on the paper, the inks and the press.

Variables

The formulas can use these values of the original pixel:

VariableDescription
c, m, y, kThe cyan, magenta, yellow and black ink of the original pixel, from 0 to 100. In this tool y is the yellow ink, not the vertical position.
r, g, bThe red, green and blue values of the original pixel, from 0 to 255.
aThe alpha (opacity) of the original pixel, from 0 (transparent) to 255 (opaque).
h, s, lThe hue (0 to 360), saturation (0 to 100) and lightness (0 to 100) of the original pixel, to change only some colors: abs(h - 120) < 40 ? c : 0 keeps the cyan ink only in the greens.
px, pyThe position of the pixel: px from 0 (left) to the width minus 1, and py from 0 (top) to the height minus 1.
width, heightThe size of the image, in pixels. px / width goes from 0 on the left to 1 on the right.

You can also use the constants PI (3.14159...) and E (2.71828...), with or without "Math.".

Formulas

FieldDescription
C (cyan)The new amount of cyan ink. It should give a value between 0 and 100.
M (magenta)The new amount of magenta ink, from 0 to 100.
Y (yellow)The new amount of yellow ink, from 0 to 100.
K (black)The new amount of black ink, from 0 to 100. Less black ink makes the pixel lighter without changing its hue.
A (alpha)The new alpha of the pixel, from 0 (transparent) to 255 (opaque). Values outside this range are clamped. Use a to keep the original transparency.

Values outside the range

When the formula of an ink gives a value outside the range from 0 to 100, the value is adjusted:

OptionDescription
ClampValues lower than 0 become 0, and values greater than 100 become 100. This is the best option for most edits, like y + 15.
BounceThe value keeps "bouncing" between 0 and 100: 110 becomes 90, 150 becomes 50, and 210 becomes 10.
RemainderThe value starts over from 0 when it passes 100: 110 becomes 10 and 150 becomes 50. Values between 0 and 100 are kept, so a full ink stays full.

Operators

The formulas use the syntax of Javascript expressions.

OperatorDescriptionExample
+ - * /Addition, subtraction, multiplication and division. Multiplication always needs the *: write 2 * k, not 2k.k * 0.5
**Power.100 * (k / 100) ** 2
%Remainder of the division.(px + py) % 20 < 10 ? c : 0
< > <= >= == !=Comparisons. They give 1 when true and 0 when false.(k > 50) * 100
condition ? a : bGives the first value when the condition is true (not zero) and the second value otherwise.k > 75 ? 100 : 0
&& || !Logical AND, OR and NOT, to combine conditions.m > 50 && y > 50 ? 0 : c
& | ^ ~ << >> >>>Bitwise AND, OR, XOR, NOT and shifts. The values are converted to whole numbers first.(px ^ py) % 100

Math functions

The functions of the Javascript Math object can be used with or without "Math.": Math.sin(px) and sin(px) are the same. The angles are in radians.

FunctionDescriptionExample
min(a, b, ...), max(a, b, ...)The smallest and the largest of the values.max(c, m, y)
abs(a), sign(a)Absolute value, and the sign (-1, 0 or 1). abs(h - 120) < 30 is true for the hues near 120.abs(h - 120) < 30 ? 0 : c
floor(a), ceil(a), round(a), trunc(a)Round down, round up, round to the nearest whole number, and remove the decimals.round(c / 50) * 50
sin(a), cos(a), tan(a)Sine, cosine and tangent. Also asin, acos, atan and atan2(y, x). Two cosines make the grid of dots of the halftone examples.m + 20 * sin(py / 15)
hypot(a, b, ...)The square root of the sum of the squares: hypot(px - width / 2, py - height / 2) is the distance from the center of the image.k + hypot(px - width / 2, py - height / 2) / 8
sqrt(a), cbrt(a), pow(a, b)Square root, cube root and power.10 * sqrt(k * 10)
exp(a), log(a), log2(a), log10(a)Exponential and logarithms. Also expm1(a) and log1p(a).log1p(k) * 21.6
sinh(a), cosh(a), tanh(a), asinh(a), acosh(a), atanh(a)Hyperbolic functions and their inverses. tanh makes smooth S-curves.50 + 50 * tanh((k - 50) / 25)
random()A random number between 0 and 1, different for every pixel. The same image always gets the same numbers.k + (random() - 0.5) * 10

Frequently Asked Questions (FAQ)

Can I use this tool to prepare a CMYK file for printing?

No. The tool shows the inks with the simple formulas above, and the downloaded image is a normal PNG image, with red, green and blue values. Professional software like Photoshop converts images to CMYK with a color profile (like FOGRA39 or US Web Coated SWOP), which describes the inks and the paper of a real press and gives different values. Use this tool for creative edits and to understand the inks, and ask your printer how they want the file.

Why is "y" the yellow ink and not the vertical position?

Because the four inks are called C, M, Y and K. The position of the pixel is px (horizontal) and py (vertical). A formula copied from the RGB Formula Editor that uses x gives an error here: replace x with px and y with py.

Why does a black pixel have no cyan, magenta or yellow ink?

With the simple formulas, all the darkness goes to the black ink, so black is 100% K and nothing else. Printers often add other inks under the black to make it deeper, which is called "rich black" (for example k > 90 ? max(c, 60) : c for the cyan). On the screen it makes no difference, because 100% black ink is already pure black.

Why do colored specks appear in the dark areas when I reduce the black ink?

In a very dark pixel, the cyan, magenta and yellow inks are computed from tiny differences between the red, green and blue values, which are often just compression noise of a JPEG photo. Removing the black ink makes those inks visible. Reduce the black less (k * 0.7), or keep the black of the darkest pixels: k > 85 ? k : k * 0.5.

Can I get the same images with the RGB Formula Editor?

Yes, every CMYK edit can be written with red, green and blue formulas, because the inks are computed from them. But some edits are much simpler with inks: k * 0.5 here would be a long formula for each channel in RGB. Some other edits are the same in both: swapping the cyan and the magenta is the same as swapping the red and the green.

Why doesn't the image change when I move the black ink into the other inks?

Four inks describe a color with four numbers, but a color on the screen only needs three, so different combinations of inks give the same color. For example, 100 - (100 - c) * (100 - k) / 100 for the cyan (and the same for the magenta and the yellow) with 0 for the black gives exactly the original image, printed without black ink. On a real press the result would be different, because real inks are not perfect.

How do I limit the total amount of ink?

Printers limit the sum of the four inks (for example to 300%), because too much ink doesn't dry. To scale down the inks of the pixels above a limit of 200%, multiply each ink by min(1, 200 / (c + m + y + k)), for example c * min(1, 200 / (c + m + y + k)) for the cyan.

Why do my formulas give slightly different values than a calculator?

The formulas are computed by your graphics card, with 32-bit numbers. For colors this makes no visible difference, but very large values (for example sin(px * py * 1000)) lose precision.

The image is too large. What can I do?

The size of the image is limited by your graphics card, usually to 8192 or 16384 pixels on each side. Make it smaller with Resize image first.

What is WebGL2?

WebGL2 is the technology that lets websites use your graphics card. All modern browsers support it. If the image doesn't appear, check that hardware acceleration is enabled in the settings of your browser.

Is my image uploaded to a server?

No. Your image is read and edited by your own browser, and it never leaves your computer.

Related tools

RGB Formula Editor

Edit images using math equations. Transform images by applying custom RGB formulas to each pixel.

HSL Formula Editor

Edit images using math equations for the hue, saturation and lightness of each pixel.

Change image color

Change color of images by changing the red, green and blue components of each pixel of the image.
Create images using math equations

Create images using math equations

Generate images from mathematical formulas.

Convolution Matrix

Apply a convolution matrix to images to blur, sharpen, emboss or detect edges, with ready-made or custom kernels.