Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work around jpegtran to get correct rotated crops. #82

Merged
merged 1 commit into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions cropgui_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,16 @@ def get_cropspec(image, corners, rotation):
t, l, r, b = corners
w = r - l
h = b - t
# Technically this should produce perfect crops, but jpegtran is broken
# and so mistakenly rounds out fractional crops on flipped images. Sigh.
return "%dx%d+%d+%d" % (w, h, l, t)
# Technically these parameters should straightforwardly produce perfect
# crops, but jpegtran is broken here in two regards: (1) it doesn't
# recognise perfect rotated crops as such, so the '-perfect' switch
# erroneously rejects correctly ICMU-aligned rotate-and-crop commands, and
# (2) it mistakenly rounds out crops on rotated/flipped images so that even
# the bottom right corner is ICMU-aligned. Sigh. Adding the 'f' suffixes
# to the dimensions here at least solves (2), and seems to produce the same
# results as you get by manually constructing a pipeline of '-perfect'
# command lines.
return "%dfx%df+%d+%d" % (w, h, l, t)


def ncpus():
Expand Down
9 changes: 5 additions & 4 deletions generate_test_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
dir=test
[ -d $dir ] || mkdir $dir

text='-density 72 -pointsize 32 -weight Bold -gravity NorthWest -fill rgba(255,0,0,0.5) -annotate +0+0 A -annotate +32+32 B -annotate +64+64 C -annotate +96+96 D -annotate +128+128 E -annotate +160+160 F -annotate +192+192 G -annotate +224+224 H -annotate +256+256 I -annotate +288+288 J -annotate +320+320 K -fill rgba(0,255,0,0.5) -annotate +352+352 L -annotate +384+320 M -annotate +416+288 N -annotate +448+256 O -annotate +480+224 P -annotate +512+192 Q -annotate +544+160 R -annotate +576+128 S -annotate +608+96 T -annotate +640+64 U -annotate +672+32 V -fill rgba(0,0,255,0.5) -annotate +704+0 W -annotate +736+32 X -annotate +768+64 Y'
convert -size 100x100 pattern:gray50 -scale 1600% -sampling-factor 2x2 \
-crop 796x396+0+0 $dir/chess-2x2.jpg
-crop 796x396+0+0 $text $dir/chess-2x2.jpg
convert -size 100x100 pattern:gray50 -scale 800%x1600% -sampling-factor 1x2 \
-crop 796x396+0+0 $dir/chess-1x2.jpg
-crop 796x396+0+0 $text $dir/chess-1x2.jpg
convert -size 100x100 pattern:gray50 -scale 1600%x800% -sampling-factor 2x1 \
-crop 796x396+0+0 $dir/chess-2x1.jpg
-crop 796x396+0+0 $text $dir/chess-2x1.jpg
convert -size 100x100 pattern:gray50 -scale 800% -sampling-factor 1x1 \
-crop 796x396+0+0 $dir/chess-1x1.jpg
-crop 796x396+0+0 $text $dir/chess-1x1.jpg