Skip to content

Commit ebd2cd7

Browse files
authored
Merge pull request #462 from menschmaschine/master
Cropping guide for German passport and ID card photos.
2 parents 19fdbc1 + 52b4508 commit ebd2cd7

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

contrib/passport_guide_germany.lua

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
--[[
2+
German passport photo cropping guide for darktable.
3+
Derived from the passport cropping guide by Kåre Hampf.
4+
5+
copyright (c) 2017 Kåre Hampf
6+
copyright (c) 2024 Christian Sültrop
7+
8+
darktable is free software: you can redistribute it and/or modify
9+
it under the terms of the GNU General Public License as published by
10+
the Free Software Foundation, either version 3 of the License, or
11+
(at your option) any later version.
12+
13+
darktable is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
GNU General Public License for more details.
17+
18+
You should have received a copy of the GNU General Public License
19+
along with darktable. If not, see <http://www.gnu.org/licenses/>.
20+
]]
21+
22+
--[[
23+
PASSPORT CROPPING GUIDE
24+
Guides for cropping passport and ID card ("Personalausweis") photos based on the "Passbild-Schablone"
25+
from the German Federal Ministry of the Interior and Community.
26+
(https://www.bmi.bund.de/SharedDocs/downloads/DE/veroeffentlichungen/themen/moderne-verwaltung/ausweise/passbild-schablone-erwachsene.pdf?__blob=publicationFile&v=3)
27+
28+
INSTALLATION
29+
* copy this file in $CONFIGDIR/lua/ where CONFIGDIR is your darktable configuration directory
30+
* add the following line in the file $CONFIGDIR/luarc
31+
require "passport_guide_germany"
32+
* (optional) add the line:
33+
"plugins/darkroom/clipping/extra_aspect_ratios/passport 35x45mm=45:35"
34+
to $CONFIGDIR/darktablerc
35+
36+
USAGE
37+
* when using the cropping tool, select "Passport Photo Germany" as guide and if you added the line in yout rc
38+
select "passport 35x45mm" as aspect
39+
]]
40+
41+
local dt = require "darktable"
42+
local du = require "lib/dtutils"
43+
local gettext = dt.gettext
44+
45+
du.check_min_api_version("2.0.0", "passport_guide_germany")
46+
47+
-- Tell gettext where to find the .mo file translating messages for a particular domain
48+
gettext.bindtextdomain("passport_guide_germany",dt.configuration.config_dir.."/lua/locale/")
49+
50+
local function _(msgid)
51+
return gettext.dgettext("passport_guide_germany", msgid)
52+
end
53+
54+
dt.guides.register_guide("Passport Photo Germany",
55+
-- draw
56+
function(cairo, x, y, width, height, zoom_scale)
57+
local _width, _height
58+
59+
-- get the max 35x45 rectangle
60+
local aspect_ratio = 45 / 35
61+
if width * aspect_ratio > height then
62+
_width = height / aspect_ratio
63+
_height = height
64+
else
65+
_width = width
66+
_height = width * aspect_ratio
67+
end
68+
69+
cairo:save()
70+
71+
cairo:translate(x + (width - _width) / 2, y + (height - _height) / 2)
72+
cairo:scale(_width / 35, _height / 45)
73+
74+
-- the outer rectangle
75+
cairo:rectangle( 0, 0, 35, 45)
76+
77+
-- Nose position: The nose tip must be between these lines
78+
cairo:draw_line(15.5, 45, 15.5, 13)
79+
cairo:draw_line(35-15.5, 45, 35-15.5, 13)
80+
81+
-- Face height
82+
-- optimum face height: The upper end of the head should be between these lines
83+
cairo:draw_line(0, 4, 35, 4)
84+
cairo:draw_line(0, 8, 35, 8)
85+
86+
-- tolerated face height: The upper end of the head must not be below this line
87+
cairo:draw_line(6, 13, 30, 13)
88+
89+
-- Eye area: The eyes must be between these lines
90+
cairo:draw_line(0, 13, 35, 13)
91+
cairo:draw_line(0, 23, 35, 23)
92+
93+
-- Cheek line: The cheek must lie on this line
94+
cairo:draw_line(9, 45-5, 27, 45-5)
95+
96+
cairo:restore()
97+
end,
98+
-- gui
99+
function()
100+
return dt.new_widget("label"){label = _("Passport Photo Germany"), halign = "start"}
101+
end
102+
)
103+
104+
-- kate: tab-indents: off; indent-width 2; replace-tabs on; remove-trailing-space on; hl Lua;
105+
-- vim: shiftwidth=2 expandtab tabstop=2 cindent syntax=lua

0 commit comments

Comments
 (0)