Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open a jpg, mod jpg, close and save jpg 2

Status
Not open for further replies.

cfsjohn

Programmer
Sep 1, 2016
59
0
6
US
I have a Topaz signature pad. It captures the customer's signature at the end of a sale. It can save the signature to a string (it is a very long string), a sig file which I guess would be Topaz proprietary, bmp, jpg, png, tiff and wmf and emf. I have it saving the signatures as an jpg image file. It works. I can print the jpg on the receipt (a VFP9 report). My problem is the signature is very small. I can't find a way via Topaz commands to make the signature larger. The jpg file contains a lot of whitespace aroung the actual signature. If I could somehow (from VFP), open the jpg, find the 1st instance of a black dot in the jpg (that would be where the actual signature starts), maybe I could automatically crop the jpg and resave it ending up with an image that ONLY contains the actual signature (so leaving out all the whitespace around the actual signature). I've looked at using the VFP GDIPlus library and maybe the GDIPlus X library on github (i really don't understand how to download that library from github).

Can anyone tell me the easiest way to get from point a to b on this?

Thanks,
John
 
 https://files.engineering.com/getfile.aspx?folder=af0e6a10-6d0f-4327-bc8a-1069e3407836&file=00598934.jpg
I think you may be over analysing this.

If the image is AWAYS small, and has this white space around it, does it EVER creep into the top left or bottom right?

If not, surely you could zoom in by a factor and/or crop it to suit.

Me, I would use Viscomsoft ImageViewer to do the work.

Why, because I bought a licence years ago, and it still works!




Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0
 
Griff, You may very well be correct about over analyzing. Been on this for days. I am a bit frustrated.

You said to zoom. I do not recall anything about how to zoom. Can you elaborate?

Thanks, John
 
John,

Can we assume that the amount of white space around the signature is constant? In other words, is the actual signature always in the same place relative to the edges of the image?

If so, it should be possible to do this by sizing the image control to fit the actual signature, and setting its Stretch property to 1.

However, the fact that you mention having to find the first dot suggests that the above assumption is wrong. In that case, you will indeed have to resort to GDI Plus. Have you looked at the base _GDIPLUS.vcx class library that comes with VFP? There might well be something there that will help. There is more information in the VFP Help file, starting at the topic, "GDI Plus API Wrapper Foundation Classes".

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Keeping in mind that I am definitely not an expert on GDI Plus ....

But glancing at the documentation for the GDI Plus Bitmap Foundation Class, it appears that you could call its CreateFromFile() method to get a bitmap object from your JPG file. Then use its GetPixel() method to loop through the pixels to find where the signature actually starts and ends.

Actually, it's probably more complicated than that. But at least it's a starting point. No doubt there are people in the forum who can give you more detailed advice.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike,
Yes, the amount of whitespace aroung the signature IS constant.

I have attached a screenprint showing the settings for the picture control on my report. I have tried all 3 settings, clip contents prints nothing, scale contents (both of them) prints the very small signature. I can make the control taller in which case I do get a bigger sihnature but it still prints the whitespace so it consumes a lot more receipt paper.

I will see if I can understand how to use the GDI library.

Thanks,
John
 
I think we would all profit from a real world example. What if you use such a pad, scribble something on it (doesn't need to be your or anybodies real signature) and post an image here. Make it two examples, please.

I wonder whether all images have the same size, for example, no matter how small or large the actual scribble is. If so, that would even make zooming questionable, you would just need a report image object with fixed size that prints the sccanned image as is, the size would just vary by how large the customer or whatever person signs on the pad and there's no more detail to be gained from zooming in, really.

From your description, I think the only reason to program cropping is to save space in storing the image, In case of JPEG the image compression will already take care compressing vast regions of whitespace, only raw BMP would have a fixed file size.

I understand for you its about the readability of the printed signature. I just guess if a customer only makes a little x or dot, you don't get more detail out of it by zooming that. Instead, you just need a larger size of the image control on the report, than you think.

And I really wonder why images sizes of such signatures would differ, if so, then only when the pad itself would crop the image. As far as you tell this isn't the case, though, so I assume they all have the same standard size. And then I would simply try to make the report control for the image full page width, aspect ratio the same as the images have and then the signature should come out with a reasonable size at whatever position the cutomer signed within that rectangle.

And then, it mainly becomes an instruction to whoever gives this pad to the people signing to ask them to make use of the whole area, to improve the quality.

Chriss
 
@John

The 'zoom' is not a function of VFP, but I believe it is in the imageviewer, if not an actual zoom it lets you save a file in a given size.

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0
 
Sorry, I wasn't aware your attachment is an example.

Seems to me it is always 2000x700, right? Is the problem, that you don't print on letter size? Because I think this would come out fine, if the report would be lettersize and the image control width would be paper width. The position and size of the signature would then just be as was used writing on the pad.

I don't have any idea how large the pads are, but the way the image is I assume the pad area is way larger than necessary to sign, is it? So signatures are only made on a small portion of the available area. That would explain it.

I can understand you'd like to treat a signature image as mainly containing the signature (cropped) and then only need to place a control on the report as large as you want the signature, but the way it is it only makes sense to print full width, which prints the signature in reasonable size. Do you have problems with the white being opaque, hiding report content, if you do that? Or is the receipt you print just much narrower than the pad?

Chriss
 
I tried adding an attachment that is a screenprint (also a jpg) to show my report with the control, but for some odd reason, after editing my reply twice and adding the attachment twice, the Tek-Tips site did not add the attachment. I will try again to add it to this reply.

I am printing on a Epson TM-T88V receipt printer like most convenience stores use. As I said earlier, I can make the control bigger and get desirable results but because it still prints the entire image (whitespace included), that consumes a lot more receipt paper (not desirable).

As for is it "always 2000x700", I suspect it would always be the same size as the Topaz pad saves the signature as everything inside the signing area of the pad.
I did a signature where 1. I drew a box that is basically the entire signing area on the Topaz pad then 2. I signed filling the entire area. It is attached.
John



 
 https://files.engineering.com/getfile.aspx?folder=f2be1725-d356-453e-b8f6-9cf712e1d839&file=screenprint1.jpg
Do I get this right?

The screenshot of the receipt with the "John Cook" signature in a box is the image you made using the full pad size?
The image on your report layout is much higher than the aspect ratio of the image, so you just need to reduce the height of the report image control. The aspect ratio of your layout does not reflect 2000:700, that would looks slimmer. Roughly, 2000:700 means the height should be a third of the width, as 3x700=2100 is about 2000.

Well, and you know better than us, whether all pad images have that resolution. I think so.

You can also move the image control to the back usging the menu "Format" and the option "Send to back" (CTRL+J). That way you would not need to care about the image being mostly white, your other report controls simply print over that white area. Let the image overalap with other report controls.

Chriss
 
Genius, not thinking outside the box, making the box outside the other thing

Well done Olaf

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0
 
Chriss, Olaf is correct. Sometimes I can't see the forest for the trees. I modified the height and width ratio so it is 3 x as wide as it is tall and I move the control to background and VOILA! Success!

Thank you so much,
John
 
If you want I can provide you a DLL that will open the file, and give you commands to manipulate it. Something like this:

Code:
DECLARE INTEGER bmp_open_file       IN image.dll STRING cPathname
DECLARE INTEGER bmp_crop_to_content IN image.dll INTEGER nHandle
DECLARE INTEGER bmp_get_dimensions  IN image.dll INTEGER nHandle, STRING@ cWidthOutInches8, STRING@ cHeightOutInches8
DECLARE INTEGER bmp_resize          IN image.dll INTEGER nHandle, FLOAT nNewWidthInches, FLOAT nNewHeightInches
DECLARE INTEGER bmp_save_file       IN image.dll INTEGER nHandle, STRING cNewBmpPathname
DECLARE INTEGER bmp_close           IN image.dll INTEGER nHandle

* In your code:
LOCAL lnHandle, lcWidth, lcHeight, lnNewWidth, lnNewHeight
lnHandle = bmp_open_file("c:\path\to\whatever.jpg")
bmp_crop_to_content(lnHandle)
lcWidth = SPACE(8)
lcHeight = SPACE(8)
bmp_get_dimensions(lnHandle, @lcWidth, @lcHeight)

* Compute your scale factor, and generate the new height / width you want
lnNewWidth = ...
lnNewHeight = ...
bmp_resize(lnHandle, lnNewWidth, lnNewHeight)
bmp_save_file(lnHandle, "c:\temp\sig_img.bmp")
bmp_close(lnHandle)

Something like that. If interested, let me know.

--
Rick C. Hodgin
 
Hi Rick and thanks for the offer. As I will have hundreds of these image files generated daily, I believe it would be a good idea to do whatever I can that would reduce the size of the files. Your tool sounds like it could help me accomplish that so Yes, I am interested.
Thanks,
John
 
I apologize for not getting back to you sooner. I was injured yesterday playing softball and am in a bit of pain today. I'll try to get you the DLL and source code by the end of this weekend.

Again, my apologies, John.

--
Rick C. Hodgin
 
Not a problem. Hope your injury is not too bad. Take your time,
John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top