Skip to content

Instantly share code, notes, and snippets.

@poxip
poxip / img2pdf.py
Created September 5, 2019 09:14
A simple way to convert any image to PDF with Pillow
import sys
from PIL import Image
image = Image.open(sys.argv[1])
background = Image.new("RGBA", image.size, (255, 255, 255))
composite = Image.alpha_composite(background, image).convert("RGB")
composite.save(sys.argv[2], "PDF")
@poxip
poxip / string-format.js
Last active February 25, 2016 23:13
Python-like string format in JavaScript
/**
* Python-like string format function
* @param {String} str - Template string.
* @param {Object} data - Data to insert strings from.
* @returns {String}
*/
var format = function(str, data) {
var re = /{([^{}]+)}/g;
return str.replace(/{([^{}]+)}/g, function(match, val) {
@poxip
poxip / file1.py
Last active August 29, 2015 14:13
gisht: Issue #2
#!/usr/bin/env python
print("file1.py")