I have a need to select a portion of a .png file, with specific cordinators, and delete this area then save the file back with the same name. I would appreciate if you can help to come up with a VBScript script that can accomplish this task. It would be great if all proesses happen in the background, but it would be ok too if the image file has to be open and visible. Thanks a bunch!!!
2 Answers
A PNG file, like any other binary file can be edited with CMD or VBS.
A PNG file layout is as follows:
- File header
- "Chunks" within the file
- Pixel format
- Transparency of image
- Compression
- Interlacing
- Animation
Read the PNG format in RFC 2083 to know how to edit/create a PNG file at binary/bit level.
To speed up the editing process, libraries are available for application level editing. Here are some VBA codes for image manipulation.
ImageMagick also provides libraries that can be accessed via VBS for image editing.
Here's a VBScript Image Class for bmp and pcx files (which PNG can be converted to before editing via WIA). Loadpicture function described here doesn't seem to support PNG, but this discussion might solve it.
The Windows Image Acquisition Library v2.0 supports PNG, BMP, JPG, GIF and TIFF image formats, and comes with Windows Vista and later versions. Sample scripts are available to demonstrate "image manipulation using the ImageFile object". The Vector.ImageFile property also "creates an ImageFile object from raw ARGB data".
More sample codes here & here show how to rotate, flip, scale, crop, etc with WIA Image constants in vbs. To remove unwanted areas of image (with given coordinates), use the crop function.
Here's a discussion of WIA 2.0 image editing on stackoverflow.

- 2,854
- 18
- 26
VBScript doesn't have any image editing functions, so you need an external tool for that. For example, GIMP can do image processing from the command line (see here). ImageMagick provides a scriptable component in addition to the command-line interface (details here).
To run a command line from a VBScript script, you can use the WShShell.Run
method. To create an instance of a COM scriptable component, use the CreateObject
function.

- 87,344
- 17
- 243
- 314
-
1Well, you can read/write files with vbscript. So, if you know how to locate the pixel data within your .png files, you can modify it. To do so, you would basically make your own png file parser. Once you had such a parser, you would have to translate your two x,y coodinates into the locations of all those pixels in the file and change their values. png files are very complex, however. They can be flat or have layers, and they can have a transparency channel. The things I mention above aren't trivial. I think the answer above will get you what you want. – George Sisco Feb 04 '10 at 21:00
-
Did you come here to stop others from answering this question, or did you just feel like leaving something that hopefully became selected as an answer? This is a comment, not an answer. – Zimba Nov 25 '20 at 06:18