RE: Image Remove Perimeter White Space

2018-12-26 Thread Ralph DiMola via use-livecode
Thanks!
I'll give it a try in the am. All of the images are 512/512 or less(icons).

Ralph DiMola
IT Director
Evergreen Information Services
rdim...@evergreeninfo.net
Phone: 518-636-3998 Ex:11
Cell: 518-796-9332


-Original Message-
From: use-livecode [mailto:use-livecode-boun...@lists.runrev.com] On Behalf
Of hh via use-livecode
Sent: Wednesday, December 26, 2018 7:58 PM
To: use-livecode@lists.runrev.com
Cc: hh
Subject: Re: Image Remove Perimeter White Space

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



___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Image Remove Perimeter White Space

2018-12-26 Thread hh via use-livecode
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



___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Image Remove Perimeter White Space

2018-12-26 Thread hh via use-livecode
> Ralph wrote:
> I will just have to go pixel by pixel and check
> left, top, right and bottom sides for any non-zero
> RGB and delete rows/columns until one of the sides
> has an RGB that is not zero.

Here is a comparison value for that.
Using javascript from a hidden browser widget autocropping
to opaque pixels needs (incl. transport) for a 500x500 sized
image around 100 ms.


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


RE: Image Remove Perimeter White Space

2018-12-26 Thread Ralph DiMola via use-livecode
Thanks All!

I was not totally clear. The area around the visible center is
transparent(not white). I need to do this invisibly in real-time without
user interaction. Luckily all the images are square so I don't have to worry
about keeping the aspect ratio intact. I will just have to go pixel by pixel
and check left, top, right and bottom sides for any non-zero RGB and delete
rows/columns until one of the sides has an RGB that is not zero.

Again... Just when I find myself "WAH"ing I remember this is LiveCode and
things like this are not so bad to code.

Ralph DiMola
IT Director
Evergreen Information Services
rdim...@evergreeninfo.net


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Image Remove Perimeter White Space

2018-12-26 Thread J. Landman Gay via use-livecode

On 12/26/18 5:13 PM, Ralph DiMola via use-livecode wrote:

I am downloading various images from a customer with varying unpredictable
amount of white space around the image. I want to make the visible center
portion images the same size. Before I start coding is there any native LC
way or existing example stacks that do this?


If you mean to make all the images the same size and you aren't 
concerned about leaving out some content, then I'd create a temporary 
graphic with the right dimensions, center it over the loc of the 
customer image, and then:


crop img "customerImg" to the rect of grc "tempGrc"

If you want all the content to display, you can resize the longer edge 
of the image proportionately to fit inside the crop rectangle before 
cropping it.


--
Jacqueline Landman Gay | jac...@hyperactivesw.com
HyperActive Software   | http://www.hyperactivesw.com

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Image Remove Perimeter White Space

2018-12-26 Thread hh via use-livecode
> Ralph D.wrote
> I am downloading various images from a customer with
> varying unpredictable amount of white space around the
> image. I want to make the visible center portion images
> the same size.

Assuming the white space around is symmetric, at least proportional
to width and height, you could compute your "visible center portion"
based on the loc of the image. Then use the crop command.

The only difficulty with crop is to set the rectangle correctly. For
this, setting the topleft of the image to (0,0) is helpful for me.

For visible cropping you could wait for my cropTool that is able
to crop solid color background (with selectable tolerance). It's
coming in January 2019 (as a new years gift for the community) and
already done, needs only more help and some "beautifying".

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Image Remove Perimeter White Space

2018-12-26 Thread Bob Sneidar via use-livecode
Oh that's a pickle! Nothing native I'm sure. There is no telling from the image 
itself that you want "white" to equal "overlap" at least not without a mask of 
some sort. So it's going to be a pixel by pixel job, and then hope and pray 
that "white" actually means "0,0,0" as opposed to "1,0,0" or anything else. If 
the image was produced taking into account any kind of color workflow, that 
will likely not be the case. 

I suppose a better way would be to provide the end user with some kind of crop 
tool and let them draw and scale a transparent rectangle with visible border 
and handles, then crop the imported image accordingly. 

Alternatively just require the user to provide images of a maximum width and 
height, then alert the user if they select something which exceeds the 
parameters. That is not unusual to expect that from end users. For instance, 
Toshiba's new Elevate Web Portal allow the importing of a background image and 
a company logo, but the logo must be no larger than 256x256 and the background 
must be exactly a certain size. Toshiba has no compunction requiring us to 
follow those guidelines. 

Bob S


> On Dec 26, 2018, at 15:13 , Ralph DiMola via use-livecode 
>  wrote:
> 
> I am downloading various images from a customer with varying unpredictable
> amount of white space around the image. I want to make the visible center
> portion images the same size. Before I start coding is there any native LC
> way or existing example stacks that do this?
> 
> Thanks!
> 
> Ralph DiMola


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode