Negate (Invert Colors)

Create negative (inverted) image by reversing all colors. The negate command transforms images by inverting pixel values, creating effects reminiscent of photographic film negatives, X-ray images, or unique artistic styles.

Installation

To install the Image plugin:

Terminal
$ npm install -g @mediaproc/image

Usage

Terminal
$ mediaproc image negate <input> [options]

Basic Usage

Terminal
$ mediaproc image negate photo.jpg
✓ Created negative image
$ mediaproc image negate image.png --alpha
$ mediaproc image negate pic.jpg -o inverted.jpg
$ mediaproc image negate photo.jpg --dry-run

Options

OptionAliasTypeDefaultDescription
--output <path>-ostring<input>-negated.<ext>Output file path
--quality <quality>-qnumber90Output quality (1-100) for lossy formats
--alphabooleanfalseAlso negate alpha/transparency channel
--dry-runbooleanfalseShow what would be done without executing
--verbose-vbooleanfalseShow detailed processing information
--helpbooleanfalseDisplay help information

How Negate Works

The negate operation inverts pixel values using simple subtraction from maximum:

Formula: output_value = 255 - input_value

RGB Inversion

For each color channel (Red, Green, Blue):

  • Black (0) becomes White (255)
  • White (255) becomes Black (0)
  • Mid-gray (128) stays Mid-gray (127)

Color Transformations

  • Red (255, 0, 0) → Cyan (0, 255, 255)
  • Green (0, 255, 0) → Magenta (255, 0, 255)
  • Blue (0, 0, 255) → Yellow (255, 255, 0)
  • Cyan (0, 255, 255) → Red (255, 0, 0)
  • Magenta (255, 0, 255) → Green (0, 255, 0)
  • Yellow (255, 255, 0) → Blue (0, 0, 255)

Alpha Channel

By default, alpha (transparency) is preserved. Use --alpha flag to also invert transparency:

  • Fully opaque (255) becomes fully transparent (0)
  • Fully transparent (0) becomes fully opaque (255)

Examples

1. Basic Color Inversion

Create standard negative image:

mediaproc image negate photo.jpg

Result: Outputs photo-negated.jpg with all colors inverted.

2. Custom Output Location

Specify exact output path:

mediaproc image negate portrait.jpg -o negative-portrait.jpg

Control: Full control over output filename and location.

3. Invert with Alpha

Invert both colors and transparency:

mediaproc image negate transparent-image.png --alpha

Effect: Colors and transparency are both reversed.

4. High-Quality Output

Preserve maximum quality:

mediaproc image negate important-photo.jpg -q 100

Quality: Lossless compression for best results.

5. Batch Processing

Invert multiple images:

mediaproc image negate "photos/*.jpg"

Output: Creates *-negated.jpg for each input file.

6. X-Ray Style Effect

Create medical imaging aesthetic:

mediaproc image negate medical-image.png -o xray-style.png

Aesthetic: Popular for artistic or technical visualization.

7. Dark Mode Conversion

Convert light images to dark theme:

mediaproc image negate light-diagram.png -o dark-diagram.png

UI/UX: Quick dark mode variations.

8. Film Negative Effect

Recreate analog photography look:

mediaproc image negate digital-photo.jpg -o film-negative.jpg

Vintage: Classic film photography aesthetic.

9. Preview Before Processing

Check effect before creating file:

mediaproc image negate photo.jpg --dry-run

Safety: Verify settings and output path.

10. Artistic Surreal Effects

Create unusual color combinations:

mediaproc image negate landscape.jpg -o surreal-landscape.jpg

Art: Otherworldly, psychedelic appearance.

11. Double Negative (Return to Original)

Negate twice to return to original:

# First negation
mediaproc image negate photo.jpg -o negative.jpg

# Second negation (back to original)
mediaproc image negate negative.jpg -o restored.jpg

Reversible: Lossless color transformation (excluding compression).

12. Technical Visualization

Enhance visibility of certain features:

mediaproc image negate technical-diagram.png

Analysis: Sometimes inverted colors reveal hidden details.

13. PNG with Transparency

Handle transparent images correctly:

# Preserve transparency (default)
mediaproc image negate logo.png -o inverted-logo.png

# Invert transparency too
mediaproc image negate logo.png --alpha -o fully-inverted-logo.png

Flexibility: Choose transparency handling.

14. WebP Format

Invert modern image format:

mediaproc image negate image.webp -o negative.webp -q 95

Modern: Supports all contemporary formats.

15. Verbose Output

See detailed processing information:

mediaproc image negate photo.jpg --verbose

Debugging: Shows dimensions, format, and processing steps.

Use Cases

1. Artistic Effects

Create unique visual styles:

mediaproc image negate portrait.jpg -o artistic-portrait.jpg

Creative: Instantly recognizable, striking appearance.

2. X-Ray Style Imagery

Medical or technical aesthetic:

mediaproc image negate photo.png -o xray-effect.png

Professional: Popular in medical, scientific contexts.

3. Film Negative Reproduction

Traditional photography look:

mediaproc image negate digital-scan.jpg -o film-negative.jpg

Vintage: Recreate analog film appearance.

4. High Contrast Visualization

Alternative viewing mode for complex images:

mediaproc image negate complex-diagram.png

Analysis: Sometimes easier to see certain details inverted.

5. Dark Mode Themes

Convert light-themed graphics:

mediaproc image negate light-icon.png -o dark-icon.png

UI Design: Quick dark theme alternatives.

6. Psychedelic Art

Create surreal color effects:

mediaproc image negate nature-photo.jpg -o psychedelic-art.jpg

Artistic: Unusual, attention-grabbing colors.

7. Scientific Imaging

Technical visualization enhancement:

mediaproc image negate microscope-image.png

Research: May enhance visibility of specific features.

8. Printing Negatives

Create printable film negatives:

mediaproc image negate photo.jpg -o printable-negative.jpg -q 100

Alternative Process: For contact printing or other analog techniques.

9. Educational Demonstrations

Teaching color theory:

mediaproc image negate color-wheel.png

Learning: Shows complementary color relationships.

10. Social Media Content

Create eye-catching posts:

mediaproc image negate regular-photo.jpg -o viral-content.jpg

Marketing: Unique, scroll-stopping appearance.

Combining with Other Commands

Negate + Grayscale

Create classic negative look:

# First convert to grayscale
mediaproc image grayscale photo.jpg -o gray.jpg

# Then negate
mediaproc image negate gray.jpg -o classic-negative.jpg

Classic: Traditional black-and-white film negative.

Negate + Contrast

Enhance inverted image:

# Invert colors
mediaproc image negate photo.jpg -o inverted.jpg

# Increase contrast
mediaproc image linear inverted.jpg -a 1.3

Enhancement: Stronger visual impact.

Negate + Blur

Create soft, dreamy negative:

mediaproc image negate photo.jpg -o inverted.jpg
mediaproc image blur inverted.jpg -s 5

Artistic: Ethereal, surreal effect.

Negate + Sharpen

Enhance detail in negative:

mediaproc image negate scan.jpg -o negative.jpg
mediaproc image sharpen negative.jpg

Detail: Crisp, clear negative image.

Negate + Sepia

Alternative vintage effect:

# Create negative
mediaproc image negate old-photo.jpg -o negative.jpg

# Apply sepia tone
mediaproc image sepia negative.jpg

Vintage: Unique aged photograph appearance.

Double Negate for Lossy Compression Test

Test quality loss:

# First negate
mediaproc image negate original.jpg -q 90 -o negative.jpg

# Second negate
mediaproc image negate negative.jpg -q 90 -o restored.jpg

# Compare original.jpg vs restored.jpg to see compression artifacts

Quality Testing: Reveals compression impact.

Alpha Channel Handling

Default Behavior (Preserve Transparency)

# Colors inverted, transparency preserved
mediaproc image negate transparent-logo.png

Use When:

  • Logo or icon with transparency
  • Maintaining transparent areas
  • UI elements with alpha

Invert Alpha Flag

# Colors AND transparency inverted
mediaproc image negate transparent-logo.png --alpha

Use When:

  • Creating opposite transparency effects
  • Experimental artistic effects
  • Specific technical requirements

Comparison

# Without --alpha (transparency preserved)
mediaproc image negate logo.png -o logo-preserved-alpha.png

# With --alpha (transparency inverted)
mediaproc image negate logo.png --alpha -o logo-inverted-alpha.png

Visual Difference: Inverted alpha may make transparent areas opaque and vice versa.

Technical Details

Color Inversion Formula

For each pixel channel:

R_out = 255 - R_in G_out = 255 - G_in B_out = 255 - B_in

Example Values

Input RGBOutput RGBColor Transformation
(0, 0, 0)(255, 255, 255)Black → White
(255, 255, 255)(0, 0, 0)White → Black
(255, 0, 0)(0, 255, 255)Red → Cyan
(0, 255, 0)(255, 0, 255)Green → Magenta
(0, 0, 255)(255, 255, 0)Blue → Yellow
(128, 128, 128)(127, 127, 127)Mid-gray → Mid-gray

Alpha Channel Formula

When --alpha flag is used:

A_out = 255 - A_in

Performance

Negate is extremely fast:

  • Small image (less than 1MP): under 10ms
  • Medium image (5MP): ~20-30ms
  • Large image (20MP): ~50-100ms
  • Very efficient, per-pixel operation

Memory Usage

Minimal memory overhead:

  • Only requires input and output buffers
  • No complex calculations
  • Small images: under 50MB
  • Large images: under 200MB

Reversibility

Perfect Inversion

Negating is perfectly reversible (ignoring compression):

# Original → Negative
mediaproc image negate original.png -o negative.png -q 100

# Negative → Back to Original
mediaproc image negate negative.png -o restored.png -q 100

# original.png ≈ restored.png (except for lossy compression)

Lossy Format Considerations

With JPEG compression:

# First negate (quality loss)
mediaproc image negate original.jpg -q 90 -o negative.jpg

# Second negate (more quality loss)
mediaproc image negate negative.jpg -q 90 -o restored.jpg

# restored.jpg will differ from original.jpg due to double compression

Solution: Use PNG or high quality (95-100) for reversible operations.

Troubleshooting

Issue: Transparency Affected Unexpectedly

Problem: Transparent areas become opaque or vice versa

Solution: Don't use --alpha flag:

# This inverts transparency (usually unwanted)
mediaproc image negate logo.png --alpha

# This preserves transparency (usually desired)
mediaproc image negate logo.png

Issue: Image Looks Strange After Double Negate

Problem: Quality degradation after negating twice

Solution: Use lossless format or maximum quality:

# Use PNG (lossless)
mediaproc image negate photo.png -o negative.png
mediaproc image negate negative.png -o restored.png

# Or use maximum JPEG quality
mediaproc image negate photo.jpg -q 100 -o negative.jpg
mediaproc image negate negative.jpg -q 100 -o restored.jpg

Issue: Colors Don't Match Expected

Problem: Negate produces unexpected colors

Solution: Remember negate inverts to complementary colors:

  • Red → Cyan (not green)
  • Green → Magenta (not red)
  • Blue → Yellow (not orange)

This is correct behavior based on RGB color model.

Issue: Batch Processing Creates Too Many Files

Problem: Negated files mixed with originals

Solution: Use output directory:

# Instead of creating files in same directory
mkdir negatives
mediaproc image negate "photos/*.jpg"
# Then move outputs: mv *-negated.jpg negatives/

Issue: Effect Too Subtle or Not Working

Problem: Negate seems to have no effect

Solution: Check image already has extreme values:

# Verify input with verbose
mediaproc image negate photo.jpg --verbose

# If image is mostly mid-tones, negate will look similar
# Try on image with clear blacks/whites for dramatic effect

Best Practices

1. Test First

Use dry-run to verify settings:

mediaproc image negate photo.jpg --dry-run

Preview operation before execution.

2. Preserve Quality

Use high quality for important work:

mediaproc image negate photo.jpg -q 95

Or use PNG for lossless:

# Convert to PNG, negate, convert back
mediaproc image convert photo.jpg photo.png
mediaproc image negate photo.png -o negative.png

3. Don't Negate Alpha (Usually)

Only use --alpha when specifically needed:

# Default: preserve transparency
mediaproc image negate logo.png

# Only if you really need inverted transparency
mediaproc image negate logo.png --alpha

4. Consider Grayscale First

For classic film negative look:

mediaproc image grayscale photo.jpg -o gray.jpg
mediaproc image negate gray.jpg -o negative.jpg

5. Combine with Other Effects

Negate is more interesting combined:

# Negate + adjust
mediaproc image negate photo.jpg -o neg.jpg
mediaproc image modulate neg.jpg -b 1.2 -s 1.3

6. Use for Quick Dark Mode

Create dark variations:

# Batch convert UI elements
mediaproc image negate "light-theme/*.png"
# Rename to dark-theme versions

7. Document Artistic Settings

Record successful creative combinations:

# Surreal landscape effect
mediaproc image negate landscape.jpg -o neg.jpg
mediaproc image modulate neg.jpg -s 1.5 --hue 30
  • linear - Precise mathematical color transformations
  • modulate - Adjust brightness, saturation, hue
  • grayscale - Remove color for classic negative look
  • threshold - Black and white conversion
  • normalize - Automatic brightness normalization

Further Reading

Found an issue? Help us improve this page.

Edit on GitHub →