Skip to content

YeetTheAnson/PNGTools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PNGTools

A comprehensive command line utility for PNG image manipulation.

Table of Contents

Installation

Windows (With Git)

# Clone the repository
git clone https://github.com/YeetTheAnson/PNGTools

# Install 
pip install ./PNGTools

Windows (Without Git)

mkdir PNGTools
cd PNGTools
curl -Lo PNGTools.zip "https://github.com/YeetTheAnson/PNGTools/releases/download/new/PNGTools.zip"
tar -xf PNGTools.zip
del PNGTools.zip
cd ..
pip install ./PNGTools

Linux

# Clone the repository
sudo git clone https://github.com/YeetTheAnson/PNGTools

# Install 
sudo pip install ./PNGTools --break-system-packages

Usage

The basic syntax for PNGTools commands is:

pngtools -i <input_file> -o <output_file> -p <process>

Where:

  • -i specifies the input file
  • -o specifies the output file (optional for some operations)
  • -p specifies the process to run
  • Additional parameters may be required depending on the process

The full list is:

Usage: pngtools -i <input.png> -o <output.png> -p <operation> [options]

Required Arguments:
    -i, --input <file>          Input PNG file
    -o, --output <file>         Output PNG file (not required for info commands)
    -p, --process <operation>   Processing operation to perform on input image

    
Processing Operations:
    transparent         Remove a specific color, making it transparent
        --color <hex>           Color to make transparent (without #)
        --tolerance <percent>   Similar color tolerance (0-100)

    swap-color          Replace one color with another
        --from <hex>            Color to replace (without #)
        --to <hex>              Replacement color (without #)
        --tolerance <percent>   Similar color tolerance (0-100)

    color-tone          Convert all colors to a single tone
        --color <hex>           Target color (without #)

    opacity             Adjust the opacity of the PNG
        --level <percent>       Opacity level (0-100)

    noise               Add noise to the PNG
        --amount <percent>      Noise intensity (0-100)
        --tolerance <percent>   (Optional) Color similarity for noise

    compress            Compress the PNG file
        --level <percent>       Target compression level (0-100)

    convert             Convert image format (png, jpg, webp, base64)
                        Automatically detects format from input and output filename
    
    alpha-extract       Extract alpha channel as a silhouette
        -color <hex>            Silhouette color (without #)

    rotate              Rotate the PNG
        --angle <degrees>       Rotation angle (0-360)

    skew                Skew the PNG along X and/or Y axis
        --x <percent>           Skew amount along X-axis
        --y <percent>           Skew amount along Y-axis

    mirror              Mirror (flip) the PNG
        --horizontal            Flip horizontally
        --vertical              Flip vertically

    text                Add text to the PNG
        --text "<string>"       Text content (in quotes)
        --color <hex>           Text color (without #)
        --size <px>             Font size (in px)
        --bold                  (Optional) Bold text
        --italic                (Optional) Italic text
        --x <px>                X position
        --y <px>                Y position

    pixelate            Pixelate the PNG
        --size <px>             Pixel block size

    blur
        --radius <px>           Blur radius
    
    split-rgba          Split PNG into RGBA components
                        Outputs: <name>_R.png, <name>_G.png, etc.

    center              Center object within a transparent PNG

    border              Add a border around the PNG
        --thickness <px>        Border thickness in pixels
        --color <hex>           Border color (without #)

    round-corners       Round PNG corners (choose one mode)
        (Option 1)              Uniform radius for all corners
        --cornerradius <px>     Corner radius in px

        (Option 2)              Different radius for each corner
        --tl <px>               Corrner radius of top left corner
        --tr <px>               Corrner radius of top right corner
        --bl <px>               Corrner radius of bottom left corner
        --br <px>               Corrner radius of bottom right corner

    multiply            Duplicate the PNG
        --x <n>                 Times to repeat horizontally
        --y <n>                 Times to repeat vertically

    trim                Remove transparent space around object in PNG

    hide-text           Hide a secret message inside the PNG
        --message "<string>"    Message to conceal (in quotes)

    resize              Resize the PNG
        --width <px>            New width in pixels
        --height <px>           New height in pixels
        --no-aspect             (Optional) Don't maintain aspect ratio

    filter              Apply color filter to the PNG
        --filter-type <type>    Filter type (grayscale, sepia, negative, red, green, blue)

    crop                Crop the PNG to specified coordinates
        (Option 1)
        --left <px>             Left x coordinate
        --top <px>              Top y coordinate
        --right <px>            Right x coordinate
        --bottom <px>           Bottom y coordinate

        (Option 2)
        --topleft <x,y>         Top left coordinates
        --bottomright <x,y>     Top right coordinates

        
Information Commands (No output file required):
    analyze             Analyze the PNG file (basic metadata)
    size                Get PNG file size
    color-count         Count the number of unique colors in the PNG
    extract-hidden-text Extract hidden text from PNG
    pick-color          Get color at specific coordinates
        --x <px>                X cooridnate
        --y <px>                Y coordinate

Features

Basic Operations

Analyze Image

pngtools -i test.png -p analyze

Provides detailed information about the image including dimensions, color mode, and file size.

Get File Size

pngtools -i test.png -p size

Returns the file size of the image.

Count Colors

pngtools -i test.png -p color-count

Counts and returns the number of unique colors in the image.

Pick Color from Coordinates

pngtools -i test.png -p pick-color --x 100 --y 100

Returns the color value at the specified coordinates.

Rotate Image

pngtools -i test.png -o rotated.png -p rotate --angle 45
Before After
Original Image Rotated Image

Skew Image

pngtools -i test.png -o skewed.png -p skew --x 20 --y 30
Before After
Original Image Skewed Image

Mirror Image

pngtools -i test.png -o mirror_h.png -p mirror --horizontal
pngtools -i test.png -o mirror_v.png -p mirror --vertical
pngtools -i test.png -o mirror_both.png -p mirror --horizontal --vertical
Original Horizontal Vertical Both
Original Image Horizontal Mirror Vertical Mirror Both Directions

Add Text

pngtools -i test.png -o text.png -p text --text "Hello World" --color FF0000 --size 24 --x 50 --y 50
pngtools -i test.png -o text_bold.png -p text --text "Bold Text" --color 0000FF --size 24 --bold --x 50 --y 50
pngtools -i test.png -o text_italic.png -p text --text "Italic Text" --color 00FF00 --size 24 --italic --x 50 --y 50
Original Regular Text Bold Text Italic Text
Original Image Text Added Bold Text Italic Text

Pixelate

pngtools -i test.png -o pixelated.png -p pixelate --size 8
Before After
Original Image Pixelated Image

Blur

pngtools -i test.png -o blurred.png -p blur --radius 5
Before After
Original Image Blurred Image

Add Border

pngtools -i test.png -o border_black.png -p border --thickness 10
pngtools -i test.png -o border_red.png -p border --thickness 10 --color FF0000
Original Black Border Red Border
Original Image Black Border Red Border

Round Corners

pngtools -i test.png -o round_uniform.png -p round-corners --cornerradius 20
pngtools -i test.png -o round_varied.png -p round-corners --tl 10 --tr 20 --bl 30 --br 40
Original Uniform Corners Varied Corners
Original Image Uniform Rounded Corners Varied Rounded Corners

Multiply Image

pngtools -i test.png -o multiply_h.png -p multiply --x 3 --y 1
pngtools -i test.png -o multiply_v.png -p multiply --x 1 --y 3
pngtools -i test.png -o multiply_both.png -p multiply --x 2 --y 2
Original Horizontal Multiply Vertical Multiply Both Directions
Original Image Horizontal Multiply Vertical Multiply Both Directions

Hide and Extract Text

pngtools -i test.png -o hidden_text.png -p hide-text --message "This is a secret message"
pngtools -i hidden_text.png -p extract-hidden-text
Before After
Original Image Image with Hidden Text

Note: The image with hidden text will appear visually identical to the original. Changes are made at the pixel level and are not visible to the human eye.

Color Operations

Change Color Tone

pngtools -i test.png -o tone_blue.png -p color-tone --color 0000FF
Before After
Original Image Blue Tone

Adjust Opacity

pngtools -i test.png -o opacity_50.png -p opacity --level 50
Before After
Original Image 50% Opacity

Add Noise

pngtools -i test.png -o noise_random.png -p noise --amount 20
pngtools -i test.png -o noise_similar.png -p noise --amount 20 --tolerance 30
Original Random Noise Similar Noise
Original Image Random Noise Similar Noise

Compress Image

pngtools -i test.png -o compressed_low.png -p compress --level 20
pngtools -i test.png -o compressed_medium.png -p compress --level 50
pngtools -i test.png -o compressed_high.png -p compress --level 80
Original Low Compression Medium Compression High Compression
Original Image Low Compression Medium Compression High Compression

Warning: Compression changes may not be visibly apparent in the examples, but file sizes will be reduced. Higher compression levels may result in some visual quality loss.

Convert Formats

pngtools -i test.png -o converted.jpg -p convert
pngtools -i test.png -o converted.webp -p convert
pngtools -i test.png -o converted.txt -p convert

Note: Format conversion doesn't produce visible changes in this README but converts the image to different file formats.

Transparency Operations

Make Background Transparent

pngtools -i solid_bg.png -o transparent_bg.png -p transparent --color FFFFFF --tolerance 10
Before After
Image with Solid Background Image with Transparent Background

Swap Background Color

pngtools -i solid_bg.png -o swapped_bg.png -p swap-color --from FFFFFF --to 00FF00 --tolerance 10
Before After
Image with Original Background Image with Swapped Background

Center Object within Transparent PNG

pngtools -i transparent.png -o centered.png -p center
Before After
Original Transparent Image Centered Object

Trim Transparent Space

pngtools -i transparent.png -o trimmed.png -p trim
Before After
Transparent Image with Space Trimmed Image

Extract Alpha Channel

pngtools -i transparent.png -o alpha_extracted.png -p alpha-extract --color 000000
Before After
Transparent Image Alpha Channel Extracted

Advanced Operations

Split RGBA Channels

pngtools -i colorful_transparent.png -o rgba_split.png -p split-rgba
Before After (Red) After (Green) After (Blue) After (Alpha)
Colorful Transparent Image RGBA Channels Split RGBA Channels Split RGBA Channels Split RGBA Channels Split

Base64 Conversion

# Convert PNG to base64
pngtools -i test.png -o test_base64.txt -p convert

# Process base64 image
pngtools -i test_base64.txt -o restored.png -p convert
Original Restored from Base64
Original Image Restored Image

Note: The base64 conversion process should result in an identical image being restored.

Advanced Testing Scenarios

Color Swapping with Different Tolerances

pngtools -i color_test.png -o swap_t5.png -p swap-color --from FF0000 --to 00FF00 --tolerance 5
pngtools -i color_test.png -o swap_t15.png -p swap-color --from FF0000 --to 00FF00 --tolerance 15
pngtools -i color_test.png -o swap_t30.png -p swap-color --from FF0000 --to 00FF00 --tolerance 30
Original Tolerance 5 Tolerance 15 Tolerance 30
Original Color Test Swap Tolerance 5 Swap Tolerance 15 Swap Tolerance 30

Transparency with Different Tolerances

pngtools -i color_test.png -o trans_t5.png -p transparent --color FF0000 --tolerance 5
pngtools -i color_test.png -o trans_t15.png -p transparent --color FF0000 --tolerance 15
pngtools -i color_test.png -o trans_t30.png -p transparent --color FF0000 --tolerance 30
Original Tolerance 5 Tolerance 15 Tolerance 30
Original Color Test Transparency Tolerance 5 Transparency Tolerance 15 Transparency Tolerance 30

Compression Testing

pngtools -i large_image.png -o comp_10.png -p compress --level 10
pngtools -i large_image.png -o comp_30.png -p compress --level 30
pngtools -i large_image.png -o comp_50.png -p compress --level 50
pngtools -i large_image.png -o comp_70.png -p compress --level 70
pngtools -i large_image.png -o comp_90.png -p compress --level 90
Original 10% Compression 30% Compression 50% Compression 70% Compression 90% Compression
Original Large Image 10% Compression 30% Compression 50% Compression 70% Compression 90% Compression

Warning: Visual differences may be subtle or not visible in the preview images, but file size differences will be significant. Higher compression levels may introduce quality loss, especially at 70% and 90%.

Text Hiding with Different Image Sizes

pngtools -i small.png -o small_hidden.png -p hide-text --message "Short message"
pngtools -i medium.png -o medium_hidden.png -p hide-text --message "This is a medium length message with some details."
pngtools -i large.png -o large_hidden.png -p hide-text --message "This is a longer message that contains more information. It should test the capacity of the steganography algorithm to hide larger amounts of text data within the image pixels."
Small Original Small with Hidden Text
Small Original Image Small Image with Hidden Text
Medium Original Medium with Hidden Text
Medium Original Image Medium Image with Hidden Text
Large Original Large with Hidden Text
Large Original Image Large Image with Hidden Text

Note: Images with hidden text will appear identical to their originals. The text is encoded at the pixel level and is not visible to the human eye. Larger images can store more hidden text.

Image resize

pngtools -i cat.png -o cat_resized.png -p resize --width 500 --height 500
Before After
Cat Resized Cat

Filter

pngtools -i cat_resized.png -o cat_resized_grayscale.png -p filter --filter-type grayscale
pngtools -i cat_resized.png -o cat_resized_sepia.png -p filter --filter-type sepia
pngtools -i cat_resized.png -o cat_resized_negative.png -p filter --filter-type negative
pngtools -i cat_resized.png -o cat_resized_red.png -p filter --filter-type red
pngtools -i cat_resized.png -o cat_resized_green.png -p filter --filter-type green
pngtools -i cat_resized.png -o cat_resized_blue.png -p filter --filter-type blue
Before Grayscale Sepia negative red green blue
Base image Grayscale Sepia Negative Red Green Blue

Crop

pngtools -i cat_resized.png -o cat_resized_cropped.png -p crop --left 50 --right 450 --top 50 --bottom 450
pngtools -i cat_resized.png -o cat_resized_cropped_alt.png -p crop --topleft 50,50 --bottomright 450,450
Before 4 Point Crop 2 Point Crop
Cat 4P Cropped Cat 2P Cropped Cat

Edge Cases

Operations on Tiny Images

pngtools -i tiny.png -o tiny_processed.png -p pixelate --size 2
Before After
Tiny Original Image Tiny Processed Image

Operations on Very Large Images

pngtools -i very_large.png -o large_processed.png -p compress --level 80
Before After
Very Large Original Image Very Large Processed Image

Tip: Processing very large images may take significant time and memory. Consider using compression before other operations for better performance.

Extreme Blur

pngtools -i test.png -o extreme_blur.png -p blur --radius 50
Before After
Original Image Extremely Blurred Image

Extreme Noise

pngtools -i test.png -o extreme_noise.png -p noise --amount 100
Before After
Original Image Extremely Noisy Image

Image Creation Pipeline

pngtools -i base.png -o step1.png -p swap-color --from FFFFFF --to FFFF00 --tolerance 10
pngtools -i step1.png -o step2.png -p border --thickness 5 --color FF0000
pngtools -i step2.png -o step3.png -p round-corners --cornerradius 15
pngtools -i step3.png -o step4.png -p text --text "Test Complete" --color 000000 --size 24 --bold --x 20 --y 20
pngtools -i step4.png -o final.png -p compress --level 30
Base Step 1 Step 2 Step 3 Step 4 Final
Base Image Step 1 Step 2 Step 3 Step 4 Final Result

About

A tool for manipulating PNG images

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages