8 releases

0.3.2 Sep 18, 2024
0.3.1 Apr 19, 2023
0.2.0 Nov 2, 2022
0.1.3 Sep 13, 2022
0.1.1 Jun 8, 2022

#176 in Images

MIT license

125KB
2.5K SLoC

PNGlitcher

This crate contains a library allowing you to glitch PNG images. Most of the code comes from the PNG encoder written for the wonderful Image crate. The idea here is to provide a tool similar to the Ruby gem PNGlitch for Rust. The output of an image will not be the exact same as PNGlitch, it's simply used for inspiration.

At the moment this cargo is in heavy WIP, any release could introduce breaking changes so please use this crate for having fun and create weird looking PNG images.

How to use

Duplicate

Single filter

For each occurence this algorithm will copy data from another part of the image, then force the png to use a given filter.

Params

  • input(str): The path to the input png image.
  • output(str): The path to the output png image (without extension).
  • overwrite: specify if the output file should overwrite any existing image with the same name
  • filter(u8): From 0 to 5, define the filter used when saving the image.
  • occurence(usize): Occurence of the glitch, 1 means every column of the image.
  • gap(usize): The number of column skipped before the first occurence

Examples

pnglitcher::duplicate("input1.png", "output1", true, 3,  1, 0);
pnglitcher::duplicate("input2.png", "output2", true, 0, 100, 1000);

Sample

Create a sample using duplicate algorithm for all filters for a given image

Params

  • input(str): The path to the input png image.
  • output(str): The path to the output png image (without extension).
  • overwrite: specify if the output file should overwrite any existing image with the same name
  • occurence(usize): Occurence of the glitch, 1 means every column of the image.
  • gap(usize): The number of column skipped before the first occurence

Examples

pnglitcher::duplicate_sample("input1.png", "output1", true, 1, 0);
pnglitcher::duplicate_sample("input2.png", "output2", true, 100, 1000);

Replace

Single filter

For each occurence this algorithm will replace the data with 0, then force the png to use a given filter.

Params

  • input(str): The path to the input png image.
  • output(str): The path to the output png image (without extension).
  • overwrite: specify if the output file should overwrite any existing image with the same name
  • filter(u8): From 0 to 5, define the filter used when saving the image.
  • occurence(usize): Occurence of the glitch, 1 means every column of the image.

Examples

pnglitcher::replace("input1.png", "output1", true, 0, 1);
pnglitcher::replace("input2.png", "output2", true, 4, 1);

Sample

Create a sample using duplicate algorithm for all filters for a given image

Params

  • input(str): The path to the input png image.
  • output(str): The path to the output png image (without extension).
  • overwrite: specify if the output file should overwrite any existing image with the same name
  • occurence(usize): Occurence of the glitch, 1 means every column of the image.

Examples

pnglitcher::replace_sample("input1.png", "output1", true, 1);
pnglitcher::replace_sample("input2.png", "output2", true, 10);

Variable filter

Save each lines with a different png filter.

Params

  • input(str): The path to the input png image.
  • output(str): The path to the output png image (without extension).
  • overwrite: specify if the output file should overwrite any existing image with the same name
  • random(boolean): Defines if the choice of the filter is random or sequential.

Examples

pnglitcher::variable_filter("input1.png", "output1", true, true);
pnglitcher::variable_filter("input2.png", "output2", true, false);

Wrong filter

Single filter

Force the png encoder to use a wrong filter

Params

  • input(str): The path to the input png image.
  • output(str): The path to the output png image (without extension).
  • overwrite: specify if the output file should overwrite any existing image with the same name
  • filter(u8): From 0 to 5, define the filter used when saving the image.

Examples

pnglitcher::wrong_filter("input1.png", "output1", true, 0);
pnglitcher::wrong_filter("input2.png", "output2", true, 2);

Sample

Create a sample using wrong filter algorithm for all filters for a given imageParams

  • input(str): The path to the input png image.
  • output(str): The path to the output png image (without extension).
  • overwrite: specify if the output file should overwrite any existing image with the same name

Examples

pnglitcher::wrong_filter_sample("input1.png", "output1", true);
pnglitcher::wrong_filter_sample("input2.png", "output2", true);

Dependencies

~3.5MB
~70K SLoC