#!/bin/sh # # Generate a small clipping at the specifided geometry from an image file. # Copyright (c) 2018-2019, Hiroyuki Ohsaki. # All rights reserved. # # $Id: doc-annotate-clip,v 1.2 2019/02/26 06:33:44 ohsaki Exp $ # # This code is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY. No author or distributor # accepts responsibility to anyone for the consequences of using it # or for whether it serves any particular purpose or works at all, # unless he says so in writing. Refer to the GNU Emacs General Public # License for full details. # # Everyone is granted permission to copy, modify and redistribute # this code, but only under the conditions described in the # GNU Emacs General Public License. A copy of this license is # supposed to have been given to you along with GNU Emacs so you # can know your rights and responsibilities. It should be in a # file named COPYING. Among other things, the copyright notice # and this notice must be preserved on all copies. # example: doc-annotate-clip page-1.png 0.212 0.342 clip.png # This program requires /bin/zsh and identify and convert programs # from ImageMagick (https://www.imagemagick.org/). if [ $# != 4]; then echo "usage: doc-annotate-clip iamge-file x y outfile" 2>&1 exit 1 fi infile=$1; shift rx=$1; shift ry=$1; shift outfile=$1; shift pdf_size=`identify $infile | cut -d' ' -f3` pdf_width=`echo $pdf_size | cut -dx -f1` pdf_height=`echo $pdf_size | cut -dx -f2` # FIXME: clip size should be configurable clip_w=400 clip_h=`echo $clip_w / 3 | bc` x=`echo $pdf_width \* $rx | bc` y=`echo $pdf_height \* $ry | bc` x1=`echo $x - $clip_w / 2 | bc` y1=`echo $y - $clip_h / 2 | bc` # FIXME: point size should be configurable rect_x1=`echo $x - 2 | bc` rect_y1=`echo $y - 2 | bc` rect_x2=`echo $x + 2 | bc` rect_y2=`echo $y + 2 | bc` convert $infile -fill red -draw "rectangle $rect_x1,$rect_y1 $rect_x2,$rect_y2" \ -crop ${clip_w}x${clip_h}+$x1+$y1 $outfile