Instantly share code, notes, and snippets.

View gist:9a320b24d9370913786a9e1e2f0d1ec1
% # Nearest Neighbor
% convert xc: -define filter:verbose=1 -filter box -resize 8 null: | awk '$1==0{s+=$2} $1>0{s+=$2*2} END {print s/100}'
1.01
% # Bi-Linear
% convert xc: -define filter:verbose=1 -filter triangle -resize 8 null: | awk '$1==0{s+=$2} $1>0{s+=$2*2} END {print s/100}'
1
% # Mitchell-Netravali (Bi-Cubic B:1/3, C:1/3)
% convert xc: -define filter:verbose=1 -filter mitchell -resize 8 null: | awk '$1==0{s+=$2/2} $1>0{s+=$2*2} END {print s/100}'
View imaging_resize.go
package main
import (
"flag"
"github.com/disintegration/imaging"
"image/png"
"os"
)
func main() {
View pil_imageops_equalize_gamma.py
from PIL import Image, ImageOps
import sys
import numpy as np
def gamma_correction(im, gamma):
arr = np.asarray(im)
arr = 255.0 * (arr / 255.0)**(gamma)
return Image.fromarray(np.uint8(arr))
im = Image.open(sys.argv[1])
View pil_imageops_equalize.py
from PIL import Image, ImageOps
import sys
im = Image.open(sys.argv[1])
im = im.convert("YCbCr")
yy, cb, cr = im.split()
yy = ImageOps.equalize(yy);
im = Image.merge("YCbCr", (yy, cb, cr))
View imageops_method.py
from PIL import Image, ImageOps
import sys
if len(sys.argv) < 4:
print ("Usage: python imageopt_test.py <grayscale|equalize|...> [<value>] <infile> <outfile>\n")
print (dir(ImageOps))
exit (0);
method = sys.argv[1]
if len(sys.argv) == 4:
View http_server.py
#! /usr/local/bin/python3
# https://docs.python.jp/3/library/http.server.html
# https://blog.sarabande.jp/post/81479479934
from http.server import HTTPServer, SimpleHTTPRequestHandler
[host, port] = ["0.0.0.0", 4848]
class MyHandler(SimpleHTTPRequestHandler):
def do_GET(self):
View grayscale.py
# (c) yoya@awm.jp 2018/07/05-
# ref) https://www.programcreek.com/python/example/89944/PIL.Image.frombytes
# http://pillow.readthedocs.io/en/5.2.x/reference/Image.html#PIL.Image.Image.convert
from PIL import Image
import sys
def gamma_correct(im, gamma):
if gamma == 1.0:
return im
View pentile_rgbw2.php
<?php
/*
* (c) 2017/08/21- yoya@awm.jp
* $ composer require yoya/php-svg
*/
require_once("vendor/autoload.php");
use SVG\SVGImage;
use SVG\Nodes\Structures\SVGStyle;
use SVG\Nodes\Structures\SVGDefs;
View pentile_rgb.php
<?php
/*
* (c) 2017/08/21- yoya@awm.jp
* $ composer require yoya/php-svg
*/
require_once("vendor/autoload.php");
use SVG\SVGImage;
use SVG\Nodes\Structures\SVGStyle;
use SVG\Nodes\Structures\SVGDefs;
View pentile_rgb_w.php
<?php
/*
* (c) 2017/08/21- yoya@awm.jp
* $ composer require yoya/php-svg
*/
require_once("vendor/autoload.php");
use SVG\SVGImage;
use SVG\Nodes\Structures\SVGStyle;
use SVG\Nodes\Structures\SVGDefs;