USING: byte-arrays combinator images kernel locals sequences ; IN: images ! ? :: crop ( image loc dim -- image' ) loc first2 :> ( x y ) dim first2 :> ( w h ) y h y + [a,b) [ x swap w image pixel-row-slice-at ] map [ >byte-array ] map concat image clone swap >>bitmap dim >>dim ; USING: cairo cairo.ffi combinators destructors images images.normalization kernel ; IN: cairo ! ? : write-png ( image filename -- ) [ [ clone BGRA reorder-components [ bitmap>> ] [ dim>> ] bi &cairo_surface_destroy ] dip cairo_surface_write_to_png dup CAIRO_STATUS_SUCCESS = not [ throw ] [ drop ] if ] with-destructors ;