Image Filter-er

Use the form below to filter an image using Lua! There are several examples provided below to get started on your own filter. All of this runs in your browser using webassembly! This is inspired by how texture filters in video games work.


WASM Loading... Please wait... Ensure Javascript is enabled...

If you like this image, right-click and select save to keep it.

xpx

This controls the size of the image drawn in pixels.


Your filter code to run.

First image for your code. Generally your "main" image.

Second image, optional, usually used to enhance a filter.

Third image, optional, usually used to enhance a filter.

Fourth image, optional, usually used to enhance a filter.

Fifth image, optional, usually used to enhance a filter.

Here are a list of quick scripts you can use, click "Load Code" to load the script into the form

Name Description Load Code
Black and White Turns image1 into a black and white version of itself Load Code
Hueshift Shifts the hue of image1 by hueshift Load Code
Image Warp Warps image1 by the color of image2, specifically image2's r and g for each color define how much to warp image1, and image2 color's b is whether you warp left or right, and image2's color a is whether you warp up or down Load Code
No Change Does not change the image colors, if you set the width and height in the form to the same as your source image, there will be no change. Otherwise, the image will be scaled. Load Code
Black Sine Lines Draws black sine waves on image1 Load Code
Highlight Difference Highlights differences between image1 and image2 Load Code
Ripple Warps image1 with a sine wave on the y-axis. Looks like a water ripple. Load Code
SineX Warps image1 with a sine wave on the x-axis. Load Code
Crop Crops image1 Load Code
Overlay Overlays image2 onto image1 by averaging each pixel Load Code

Lua Reference

Most standard Lua libraries are available, and there are several non-standard functions and global variables I added to help out. These are detailed below. Note that most functions expect a color in the format of a table [r,g,b,a] where the properties range 0-1, NOT 0-255.

Function/Variable Description
GetPixel(UVX,UVY,ImageIndex,OverFlowOption) Returns the color of the specified pixel. [r,g,b,a]. Where UVX is the location of the pixel on the x-plane. This is UV coordinates though, so 0-1. UVY is the location of the pixel to sample on the y-plane, also in UV coordinates. ImageIndex is the index of the image you want to sample from. Lua starts arrays at 1, so your first image is 1, and every other image increments upward. Lastly, OverFlowOption controls how the function acts if you try and sample outside the 0-1 range. There are several global variables to help with this explained in more detail below.
Overflow_Loop Global variable to define the OverFlow option when using GetPixel. In this case, if you try and sample outside the image (range 0 through 1), it will loop back to the other side of the image. (Example: Trying to sample 1.1 will return the pixel at 0.1)
Overflow_Edge Global variable to define the OverFlow option when using GetPixel. In this case, if you try and sample outside the image (range 0 through 1), it will clamp your value so you always sample the nearest edge. (Example: Trying to sample 1.1 will return the pixel at 1)
Overflow_Stop Global variable to define the OverFlow option when using GetPixel. In this case, if you try and sample outside the image (range 0 through 1), it will always return a solid black.
Overflow_Transparent Global variable to define the OverFlow option when using GetPixel. In this case, if you try and sample outside the image (range 0 through 1), it will always return a transparent color.
ImageWidth Global variable that returns the width of the final image to be drawn as you selected in the form.
ImageHeight Global variable that returns the height of the final image to be drawn as you selected in the form.
NewColor(r, g, b, a) Returns a new table to use as a color as [r,g,b,a] where r,g,b,a are in the range of 0-1
NewColorFromClassicRGB(r,g,b,a) Returns a new table to use as a color as [r,g,b,a], however this will divide each parameter by 255 to bring a color from a classic range of 0-255 to the UV range of 0-1
Add(A, B) Adds two color tables together [r,g,b,a] + [r,g,b,a] = [r,g,b,a]
Subtract(A, B) Subtracts two color tables [r,g,b,a] - [r,g,b,a] = [r,g,b,a]
Dot(A, B) Returns the dot product two color tables together [r,g,b,a] · [r,g,b,a] = [r,g,b,a]
Mod(a, b) Returns the modulus of two a by b. a % b = c
Round(num, numDecimalPlaces) Returns the rounded num by numDecimalPlaces
Min(A, B, C) Returns the lowest number from a set of 3
Max(A, B, C) Returns the largest number from a set of 3
RGBtoHSV(A) Converts a color table A to HSV format. This will still return a color table as [r,g,b,a], but r = Hue, g = Saturation, b = Value, a=alpha
HSVtoRGB(A) Converts a color table to RGB format. This will return a standard color table [r,g,b,a]
ProcessPass(x,y,uvx,uvy) This is the function you must provide. This function will run once for each pixel in your output image. Where the parameters are the x and y of the pixel currently being considered, range of 0 to output width and height, uvx and uvy which is the uv coordinates of the pixel being considered, range of 0-1. It can be used to sample other images, do math, and finally return a color for your new output image. The output must be a single RGB color in a table as in [r,g,b,a] where r,g,b,a are in a range of 0-1.

Credit

The Lua engine used in this form is gopher-lua from Yusuke Unuzuka. It is provided under the MIT license.

The MIT License (MIT)

Copyright (c) 2015 Yusuke Inuzuka

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.