Tool AndroidImageSizer: size images automatically for multi-res using

AndroidImageSizer.exe is a utility to resize png images to the proper dip sizes.

New version 1.04
Unnecessary link to not existing external reference removed, the error on image load should now gone.

New version 1.03
This (preliminary) final version now works with 9patch images.
The boundary of the 9patch will maintain it's 1 pixel width on scaling.
The calculated size is the base image size without boundary.
The parameter /8 can be used with this image format, 9patch works with 8 bit png too.

New version 1.01
This version can create 8 bit png files. Most programs save 8 bit png with only one transparency value for pixel: on or off.
But this files maintains the (almost) full alpha channel for transparency.
(Thanks to pngquant library - https://pngquant.org/).
Using 8 bit png shrinks image file size at 50-75% with mostly no or minimal visible drawbacks.

It's a command line program best used with a batch file (example batch is included).
The following parameter can be given:
  • /out:dirname The path to the res directory of your project (the final drawable-.... dir will be added)
  • /ldpi /mdpi /hdpi /xhdpi /xxhdpi /xxxhdpi Use this parameters to set the needed images. To set all modes at once use /all.
  • /copy Doesn't resize images, only copy to target directory (normally used in combination with /8 parameter).
  • /dip:size Use this parameter to set the final image size. Because mdpi has a density of 1.0, this value is the final image size in pixel for mdpi. Example: if you set /dip:40 the final mdpi image has a size of 40 pixel, the hdpi image 60 pixel and so on.
  • /8 Reduce png to 8 bit palette (256 colors) but maintain alpha channel.
  • On rectangular images the given dip size is used for the small image size. If the large size should be used use the /l parameter.
  • If you set the /m parameter the images will not processed if the target file exists and the source file has not been changed.
  • Set the /r parameter to scan subdirs also for image files.
  • The last parameter(s) is one or more source files or dirs. If you place a filename wildcards can be used. The file extension is not needed because only png files will be used. If you use a directory name all files in this directory will processed.
See the example batch file.
Make sure the source images are large enough for high quality rescaling (i'm using normally a minimum of 256 pixel).

You can download the program here: AndroidImageSizer
 
Last edited:

MaFu

Well-Known Member
Licensed User
Longtime User
Hi All,

Also you can use Android Asset Studio.

http://romannurik.github.io/AndroidAssetStudio/

Regards,
SK

Android Asset Studio is ok for one time use.
But i must upload the image, change the settings, download and unzip the result, copy to res folder, set readonly, ...

Often while development i replace images with better ones or make litte corrections. The use of AAS is a pain in this case.

With AndroidImageSizer i create a batch file once for my project. After adding/replacing/changing a source image a doubleclick on my update.bat is all i must do.
 

MaFu

Well-Known Member
Licensed User
Longtime User
A little example:
I changed the batch file for my current project to convert all images to 8 bit png.
This project contains 218 image files at the moment with a total size of 940258 bytes.
After conversion the size shrinks to 291194 bytes, less than a third.
And my apk size shrinks from 2.4 MB to 1.9 MB.
I haven't compared all images, but my random tests shows no visible differences.
 

Brian Robinson

Active Member
Licensed User
Longtime User
A little example:
I changed the batch file for my current project to convert all images to 8 bit png.
This project contains 218 image files at the moment with a total size of 940258 bytes.
After conversion the size shrinks to 291194 bytes, less than a third.
And my apk size shrinks from 2.4 MB to 1.9 MB.
I haven't compared all images, but my random tests shows no visible differences.

Sounds good... I will give this a try.
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
I designed a simple GUI (attached to this reply ) for your tool but I got error like "Resize "0.png" to 30 (short side) as 8 bit Error on image processing."
What could be the problem ?
Did I miss something ?
Also can you please test if this GUI work on your PC ?

Thanks in advance
 

Attachments

  • AndroidImageResizerGUI.jar
    280 KB · Views: 319

MaFu

Well-Known Member
Licensed User
Longtime User
It works on my pc, but your prog have errors.

For testing i created two dirs "D:\Prog\Android\ImageSizer\Test\In" and "D:\Prog\Android\ImageSizer\Test\Out".
The "In" dir is my image path and the "Out" dir my output path.
But your GUI app uses the parameter "/out:..\Prog\Android\ImageSizer\Test\Out" and therefore the output goes to "D:\Prog\Android\Prog\Android\ImageSizer\Test\Out"

On your test this error may produce an illegal path and therefore the images cannot created.

btw.: It's AndroidImageSizer not AndroidImageResizer
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
It works on my pc, but your prog have errors.

For testing i created two dirs "D:\Prog\Android\ImageSizer\Test\In" and "D:\Prog\Android\ImageSizer\Test\Out".
The "In" dir is my image path and the "Out" dir my output path.
But your GUI app uses the parameter "/out:..\Prog\Android\ImageSizer\Test\Out" and therefore the output goes to "D:\Prog\Android\Prog\Android\ImageSizer\Test\Out"

On your test this error may produce an illegal path and therefore the images cannot created.

btw.: It's AndroidImageSizer not AndroidImageResizer

Thanks for your reply .

I changed the GUI app and now it produce a batch like this

B4X:
"C:\Users\user\Desktop\AndroidImageSizer_V1.03\AndroidImageSizer.exe" /out:C:\Users\user\Desktop\AndroidImageSizer_V1.03\res /all /dip:40 /8 C:\Users\user\Desktop\AndroidImageSizer_V1.03\images
but still I get "Resize "0.png" to 30 (short side) as 8 bit Error on image processing." error
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Have you tried it without your GUI?
Have you tried it with different images?

Yes I tried the same batch produced by GUI with double clicking it.
And I have already tried different images .

If possible please upload a simple example with an image or two
 

MaFu

Well-Known Member
Licensed User
Longtime User
Here is a zip example with three images and a batch file.
Unzip it in the folder where AndroidImageSizer.exe resides and run the batch.
All three images works fine. "banana.png" and "tree.png" completely resize and shrink to 8bit in all 6 resolutions. "dice.png" shrinks to 8bit in xxhdpi and xxxhdpi only. The lower resolutions only resize but remain as 32bit image because the shrinked version would be larger.
 

Attachments

  • Test.zip
    287.6 KB · Views: 322

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Here is a zip example with three images and a batch file.
Unzip it in the folder where AndroidImageSizer.exe resides and run the batch.
All three images works fine. "banana.png" and "tree.png" completely resize and shrink to 8bit in all 6 resolutions. "dice.png" shrinks to 8bit in xxhdpi and xxxhdpi only. The lower resolutions only resize but remain as 32bit image because the shrinked version would be larger.

I tried it but unfortunately I got "Resize "banana.png" to 30 (short side) as 8bitError on image processing."
Can it be a missing dependencies ?
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Merde. It's my fault. Due to wrong compiler switch a external lib was linked.
A new program version is online, link in first post.

Thanks and here is a new GUI build if any one is interested .
 

Attachments

  • AndroidImageSizerGUI.jar
    286 KB · Views: 304

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Ok , Here is the new build .
I hope it is useful .
 

Attachments

  • AndroidImageSizerGUI.jar
    286.6 KB · Views: 313
Top