Skip to content

Instantly share code, notes, and snippets.

@ryanfb
Created January 2, 2009 05:54
Show Gist options
  • Save ryanfb/42473 to your computer and use it in GitHub Desktop.
Save ryanfb/42473 to your computer and use it in GitHub Desktop.
proc crop_to_fit {url {xoff 0} {yoff 0} {w 63} {h 79}} {set ar [expr $w./$h.]; set dims [get_image_size $url]; if [expr $xoff == -1] {set xoff [expr round([lindex $dims 0]*$ar/4)]}; if [expr $yoff == -1] {set yoff [expr round([lindex $dims 1]/$ar/4)]}; set x [expr [lindex $dims 0]-$xoff]; set y [expr [lindex $dims 1]-$yoff]; set oar [expr $x./$y.]; if [expr $oar > $ar] {set crop [magick crop $url $xoff $yoff [expr $y*$ar] $y]} else {set crop [magick crop $url $xoff $yoff $x [expr $x/$ar]]}; . $crop}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment