Skip to content

Commit d5ec7d9

Browse files
committed
Initial commit
0 parents  commit d5ec7d9

File tree

5 files changed

+100
-0
lines changed

5 files changed

+100
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea/
2+
.DS_STORE

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Pascal Reitermann
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# python-fu-cartoonify
2+
GIMP plug-in to turn a photo into a cartoon.
3+
4+
## Preview
5+
![Preview](images/preview.jpg)
6+
7+
# Installation
8+
1. Copy `python-fu-cartoonify.py` into the plug-in folder listed under `Edit > Preferences > Folders > Plug-ins`.
9+
1. On unix ensure the file can be executed as program.
10+
1. Restart GIMP, the plug-in is listed under `Filters > Artistic > Cartoonify...`
11+
12+
# License
13+
python-fu-cartoonify is licensed under the [MIT License](https://raw.githubusercontent.com/pascalre/python-fu-cartoonify/master/LICENSE).

images/preview.jpg

574 KB
Loading

python-fu-cartoonify.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
from gimpfu import *
5+
6+
7+
def apply_cartoon_filter(img, drawable):
8+
# see https://developer.gimp.org/api/2.0/libgimp/index.html
9+
# step 1: duplicate layer two times
10+
# layer2
11+
layer2 = pdb.gimp_layer_copy(drawable, False)
12+
pdb.gimp_image_add_layer(img, layer2, 0)
13+
pdb.gimp_item_set_name(layer2, "temp_merge_layer")
14+
15+
# layer3
16+
layer3 = pdb.gimp_layer_copy(drawable, False)
17+
pdb.gimp_image_add_layer(img, layer3, 0)
18+
pdb.gimp_item_set_name(layer3, "temp_sobel_operator")
19+
# set layer3 mode to GIMP_GRAIN_EXTRACT_MODE (20)
20+
pdb.gimp_layer_set_mode(layer3, 20)
21+
22+
# step 2: execute sobel operator
23+
# alternative pdb.plug_in_sobel(img, layer3, True, True, True)
24+
pdb.plug_in_edge(img, layer3, 1, 0, 0)
25+
26+
# step 3: adjust curves
27+
# see https://developer.gimp.org/api/2.0/libgimp/libgimp-gimpcolor.html#gimp-curves-spline
28+
pdb.gimp_curves_spline(layer3, 0, 6,
29+
[0, 0,
30+
130, 255,
31+
255, 255])
32+
33+
# step 4: adjust levels
34+
# see https://developer.gimp.org/api/2.0/libgimp/libgimp-gimpcolor.html#gimp-levels
35+
pdb.gimp_levels(layer3, 0, 0, 130, 1.0, 0, 255)
36+
37+
# step 5: merge layers down
38+
pdb.gimp_image_merge_down(img, layer3, 0)
39+
# set layer2 mode to GIMP_OVERLAY_MODE (23)
40+
# see https://developer.gimp.org/api/2.0/libgimp/libgimp-gimpenums.html#GimpLayerModeEffects
41+
pdb.gimp_layer_set_mode(img.layers[0], 23)
42+
pdb.gimp_image_merge_down(img, img.layers[0], 0)
43+
44+
45+
register(
46+
"python-fu-cartoonify", # Plugin name
47+
"Apply cartoon filter", # Short description
48+
"Apply cartoon filter", # Long description
49+
"Pascal Reitermann", # Plugin author
50+
"Pascal Reitermann", # Copyright or license
51+
"2022", # Year of publishing
52+
"Cartoonify...", # Name of the plug-in
53+
"*", # Supported images
54+
[
55+
(PF_IMAGE, "img", "Input image", None),
56+
(PF_DRAWABLE, "drawable", "Input drawable", None),
57+
], # Input parameter
58+
[], # Output result
59+
apply_cartoon_filter, # Name of the function
60+
menu="<Image>/Filters/Artistic"
61+
)
62+
63+
64+
main()

0 commit comments

Comments
 (0)