From 91758b61c3bf988578df38f6186084cf9404d10b Mon Sep 17 00:00:00 2001 From: khampf Date: Fri, 21 Apr 2017 13:51:40 +0300 Subject: [PATCH] ISO 19794-5/ICAO 9303 clipping guide as contrib/passport_guide.lua --- contrib/passport_guide.lua | 73 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 contrib/passport_guide.lua diff --git a/contrib/passport_guide.lua b/contrib/passport_guide.lua new file mode 100644 index 0000000..0e894f2 --- /dev/null +++ b/contrib/passport_guide.lua @@ -0,0 +1,73 @@ +--[[ +PASSPORT CROPPING GUIDE +guides for cropping passport photos based on documents from the Finnish police +(https://www.poliisi.fi/instancedata/prime_product_julkaisu/intermin/embeds/poliisiwwwstructure/38462_Passikuvaohje_EN.pdf) describing passport photo dimensions of 47x36 mm and 500x653 px for digital biometric data stored in passports. They use ISO 19794-5 standard based on ICAO 9303 regulations which should also be compliant for all of Europe. + +AUTHOR +Kåre Hampf (k.hampf@gmail.com) + +INSTALLATION +* copy this file in $CONFIGDIR/lua/ where CONFIGDIR is your darktable configuration directory +* add the following line in the file $CONFIGDIR/luarc + require "passport_guide" +* (optional) add the line: + "plugins/darkroom/clipping/extra_aspect_ratios/passport 36x47mm=47:36" + to $CONFIGDIR/darktablerc + +USAGE +* when using the cropping tool, select "passport" as guide and if you added the line in yout rc + select "passport 36x47mm" as aspect + +LICENSE +GPLv2 + +]] + +local dt = require "darktable" +dt.configuration.check_version(...,{2,0,0},{3,0,0},{4,0,0}) + +dt.guides.register_guide("passport", +-- draw +function(cr, x, y, w, h, zoom_scale) + local _w, _h + + -- get the max 36x47 rectangle + local aspect_ratio = 47 / 36 + if w * aspect_ratio > h then + _w = h / aspect_ratio + _h = h + else + _w = w + _h = w * aspect_ratio + end + + cr:save() + + cr:translate(x + (w - _w) / 2, y + (h - _h) / 2) + cr:scale(_w / 36, _h / 47) + + -- the outer rectangle + cr:rectangle( 0, 0, 36, 47) + + -- vertical bars + cr:draw_line(16.5, 8, 16.5, 36) + cr:draw_line(19.5, 8, 19.5, 36) + + -- long horisontal bars + cr:draw_line(6, 4, 30, 4) + cr:draw_line(6, 40, 30, 40) + + -- short horisontal bars + cr:draw_line(9, 6, 27, 6) + cr:draw_line(9, 38, 27, 38) + + cr:restore() +end, +-- gui +function() + return dt.new_widget("label"){label = "ISO 19794-5/ICAO 9309 passport", halign = "start"} +end +) + +-- kate: tab-indents: off; indent-width 2; replace-tabs on; remove-trailing-space on; hl Lua; +-- vim: shiftwidth=2 expandtab tabstop=2 cindent syntax=lua