Image Remove Perimeter White Space

hh hh at hyperhh.de
Wed Dec 26 19:58:08 EST 2018


Here is a pure LC Script handler from one of my "early" images stacks.
For large images this may become pretty slow...

## CROP image to opaque pixels
on cropIt ft
   put the width of img ft into w; put the height of img ft into h
   put the maskdata of img ft into mData
   put numToByte(0) into c0
   -- left and right transparency limits
   put w into cmin; put 1 into cmax
   repeat with i=0 to h-1
      put i*w into h1
      repeat with j=1 to cmin
         if byte h1+j of mData is not c0 then
            put j into cmin; exit repeat
         end if
      end repeat
      repeat with j=w down to max(cmax,cmin)
         if byte h1+j of mData is not c0 then
            put j into cmax; exit repeat
         end if
      end repeat
   end repeat
   put max(1,cmin-2) into cmin; put min(w,2+cmax) into cmax ## <- +border
   -- top and bottom transparency limits
   put h into rmin; put 1 into rmax
   repeat with j=cmin to cmax
      repeat with i=0 to rmin-1
         if byte i*w+j of mData is not c0 then
            put i into rmin; exit repeat
         end if
      end repeat
      repeat with i=h-1 down to max(rmax,rmin)
         if byte i*w+j of mData is not c0 then
            put i into rmax; exit repeat
         end if
      end repeat
   end repeat
   put max(1,rmin-2) into rmin; put min(h,2+rmax) into rmax ## <- +border
   put (cmax-cmin+1) into w1; put (rmax-rmin) into h1
   put the left of img ft into L; put the top of img ft into T
   crop img ft to L+cmin-1,T+rmin,L+cmax,T+rmax
   -- LC Bug: resizes instead of cropping when image has angle <> 0
end cropIt






More information about the use-livecode mailing list