Skip to content

Instantly share code, notes, and snippets.

@mieki256
Last active July 17, 2018 11:17
Show Gist options
  • Save mieki256/5006b98a54cb77002089 to your computer and use it in GitHub Desktop.
Save mieki256/5006b98a54cb77002089 to your computer and use it in GitHub Desktop.
GIMP Python で画像を斜めにするスクリプト
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- mode: python; Encoding: utf8n -*-
# Last updated: <2018/07/16 07:25:31 +0900>
u"""
Make oblique image.
usage: Filters -> Distorts -> Image Oblique ...
Author ; mieki256
License : CC0 / Public Domain
System Requirements :
* GIMP 2.8.10 Portable + Windows7 x64
* GIMP 2.10.2 Portable + Windows10 x64
"""
from gimpfu import * # NOQA
from array import array
import time
def _image_oblique(img, layer, sftx, sfty):
u""" add dest layer. """
x1, y1, x2, y2 = layer.mask_bounds
w = x2 - x1
h = y2 - y1
src = layer.get_pixel_rgn(x1, y1, w, h, False, False)
dst = layer.get_pixel_rgn(x1, y1, w, h, True, True)
src_pixels = array("B", src[x1:x2, y1:y2])
p_size = len(src[x1, y1])
dst_pixels = array("B", "\x00" * (w * h * p_size))
for y in range(h):
for x in range(w):
sx = (x - int(float(sftx) * y)) % w
sy = (y - int(float(sfty) * x)) % h
src_pos = (sx + w * sy) * p_size
dst_pos = (x + w * y) * p_size
v = src_pixels[src_pos: src_pos + p_size]
dst_pixels[dst_pos : dst_pos + p_size] = v
gimp.progress_update(1.0 * y / h)
dst[x1:x2, y1:y2] = dst_pixels.tostring()
layer.flush()
layer.merge_shadow(True)
layer.update(x1, y1, w, h)
def python_image_oblique(image, drawable, sftx = 1.0, sfty = 0.0, disp_time_enable = False):
gimp.progress_init("Image oblique...")
pdb.gimp_undo_push_group_start(image)
t1 = time.time()
_image_oblique(image, drawable, sftx, sfty)
if disp_time_enable:
gimp.message("Image oblique %g seconds." % (time.time() - t1))
pdb.gimp_undo_push_group_end(image)
pdb.gimp_progress_end()
pdb.gimp_displays_flush()
register(
"python_fu_image_oblique",
"Make oblique image",
"Make oblique image",
"mieki256",
"CC0 / Public domain",
"2018/07, 2015/03",
"Image Oblique...",
"RGB*, GRAY*, INDEXED",
# "*",
[
(PF_IMAGE, "image", "Input image", None),
(PF_DRAWABLE, "drawable", "Input drawable", None),
(PF_FLOAT, "sftx", "Shift x value (dot)", 1.0),
(PF_FLOAT, "sfty", "Shift y value (dot)", 0.0),
(PF_BOOL, "disp_time_enable", "Display Time", False),
],
[],
python_image_oblique,
menu="<Image>/Filters/Distorts"
)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment