How to convert an image to PVRTC format - ios

I've been using terminal to convert my jpg image named left to pvrtc format and this happens:
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/texturetool -e PVRTC --bits-per-pixel-2 -o left.pvrtc left.jpg
Failed to load image
Failed to perform Encode

Change:
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/texturetool -e PVRTC --bits-per-pixel-2 -o left.pvrtc left.jpg
To:
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/texturetool -e PVRTC --bits-per-pixel-2 -o left.pvr left.PNG
The file must be a PNG
Updated instructions on OSX 10.10+
In Terminal, hit cd to make sure you're in your root directory.
cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ && ls
This should show you a list of all the tools there (Make sure you see texturetool) - If you don't, update your OS, then Xcode
Once you know it's there, cd back to your root and run the tool like:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/texturetool -e PVRTC --bits-per-pixel-2 -f PVR -o [new path to pvr to go] [path of original png]
Your output pvr path can be ~/whatever/image.pvr and your input png is the path to your image to be converted.
HERE and HERE are other good walkthrough
The iPhone SDK includes a tool that allows you to create textures in the PVRTC compression format, aptly named texturetool. If you have Xcode installed with the iPhone OS 2.2 SDK in the default location (/Developer/Platforms/), then texturetool is located at: /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/texturetool.
texturetool allows you to create four variants of PVRTC data, the primary difference being tradeoffs between quality and size. You will have to experiment with these variants to determine which setting is the best compromise for each individual texture image.
Apple Docs
HERE is some same code to help once you have your pvrtc file
HERE are some more docs
HERE is a good read on PVRTC stuff

Related

Is there a way to compress webp file with cwebp?

I've compressed millions of jpeg files with using Google cwebp.
But some of them weirdly are bigger than the original jpeg files.
So I'm looking for a way to compress more these big webp files but couldn't find a way as cwebp is giving an error when I try to compress them again.
This is the command I'm using.
cwebp test1.webp -o test11.webp -quiet -q 50

Batch-converting of INTA images

I have a large number of images in the INTA format, an old SGI standard. INTA is a grayscale image with an alpha channel. All of these need to be converted to TGA files. The problem is that neither ImageMagick nor PIL/Pillow seem to be able to parse them correctly. ImageMagick can read and export them but doesn't seem to understand the alpha channel, and PIL fails to open them, with the error ValueError: Unsupported SGI image mode. The one thing that I've found that reads them successfully is GIMP:
An ideal solution would be one that is easy to invoke from a script.
For reference, here is one of the images in question (the same one seen in the screenshot): https://www.dropbox.com/s/8hoppdgtuqxsy26/girder01.inta?dl=0
It seems GDAL is able to read your image and I converted it to a greyscale+alpha PNG using:
gdal_convert YOURIMAGE.sgi result.png
You can easily get to TGA from there.
I am assuming the batching is not an issue, but it would look something like this in bash:
mkdir -p OUTPUT
for f in *.inta ; do
gdal_translate "$f" OUTPUT/"$f"
done
I had all sorts of trouble installing GDAL on macOS so I just used docker like this:
docker run --rm -v /Users:/Users osgeo/gdal:alpine-normal-latest gdal_translate /Users/mark/Downloads/image.sgi /Users/mark/Downloads/result.png

Cleaning up an image for OCR with ImageMagick and 'textcleaner'

I have the following image that I'd like to prepare for an OCR with tesseract:
The objective is to clean up the image and remove all of the noise.
I'm using the textcleaner script that uses ImageMagick with the following parameters:
./textcleaner -g -e normalize -f 30 -o 12 -s 2 original.jpg output.jpg
The output is still not so clean:
I tried all kinds of variations for the parameters but with no luck.
Does anyone have an idea?
If you convert to JPEG, you will always have the type of artifacts you are seeing.
This is a typical "feature" of JPEG compression. JPEGs are never good for images showing sharp lines, contrasts with uniform colors between different areas of the image, using only very few colors. This is true for black + white texts. JPEG is only "good" for typical photos, with lots of different colors and shading...
Your problem will most likely completely get resolved if you use PNG as an output format. The following image demonstrates this. I generated it with the same parameters as your last example command used, but with PNG as the output format:
textcleaner -g -e normalize -f 30 -o 12 -s 2 \
http://i.stack.imgur.com/ficx7.jpg \
out.png
Here is a similar zoom into the output:
You can very likely improve the output even more if you play with the parameters of the textcleaner script. But that is your job... :-)

How to batch convert JPG image gallery to BPG image format

How to convert whole image gallery or family album from JPG to BPG image format?
I'm looking for some batch conversion tool, application or script on Windows platform.
Input directory must be processed recursively and image quality should be preserved.
Linux command line fragment I use for this task, with current directory being gallery of '*.JPG' files, without subdirectories.
parallel -i sh -c 'convert -quality 100 {} -scale "1280x1000>" {}.png && bpgenc -q 30 {}.png -o {}.bpg && rm -f {}.png' -- *.JPG
You may adjust (or remove) resizing and change -q 30 to lower value for more quality.
It depends on ImageMagick and bpgenc.
To run in on Windows, you probably will need Cygwin.
Look at
http://www.romeolight.com/products/bpgconv/
for nice Windows converter.
2 things to mention: Currently there is options menu in top right of window. And all BPG pictures are saved into folder on your desktop called bpg_encoded.
Martin

Remove alpha channel in an image

I have an app icon for iOS but Apple doesn't allow alpha to be in the image. How to remove this alpha channel? I only have the png image with me I don't have the source file as my friend did the image for me.
The accepted answer to export to JPG, then back to PNG is not recommended.
It's an extra step in the process (2 exports)
JPG is lossy, so you will lose some image data
Here's a super fast and easy way to do this without the extra export or saving to (lossy) JPG:
Using Preview app (Mac):
Open the image
Command-Shift-S to Duplicate (creates a copy)
Command-S to Save
Deselect the "Alpha" checkbox
Delete " copy" from filename (including the space)
This will overwrite your original, if you want to keep the original, just leave "copy" in the name
Save
Click 'Replace' to confirm you want to overwrite the original
Only necessary if you are overwriting your original
if you need remove all alpha channel from directory with icons use this command:
for i in `ls *.png`; do convert $i -background black -alpha remove -alpha off $i; done
if you have Mac OS Mojave and had "convert command not found"
brew install imagemagick
To install Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null
Assuming you don't have another image editor, then you can open it in Preview on your Mac, and use the Export option to resave it in a different format- to ensure you get rid of the alpha channel, it might be best to export to JPG (best quality), then open that and export it as a PNG again.
Having said that, I suspect you're probably OK submitting an icon with a transparency channel as long as there's no actual transparency.
If you are using the Preview app, there's no need to export then re-export between jpg and png, just choose export and below the filetype (PNG) you will see an alpha checkbox, unset it and save.
You can try imagemagick (also easily resize for different sizes):
convert in.png -background black -alpha remove -alpha off -resize 1024x1024 out.png
There's no need to export the image to jpg first. You can uncheck the checkbox for the alpha channel and export directly from a png to a png without alpha channel in the preview app.
Just got the the following error when trying to upload my app to the iTunes app store:
iTunes Store Operations Failed
ERROR ITMS-90717: "Invalid App Store Icon. The App Store icon in the asset catalog in 'MyApp.app' can't be transparent nor contain an alpha channel."
I confirmed that my app store icons did include the alpha channel by locating the asset in Finder and looking up its info (⌘+i). Underneath More info, it showed:
Alpha channel: Yes
Found the solution above to use Preview to remove the alpha channel by exporting it with the Alpha checkbox unchecked, but figured a way to batch export them since I had 18 assets I needed to strip the alpha channel from.
The way I got batch exporting to work was to select all my app icon assets in finder > right click > open (or open with preview)
All of the assets will now appear in the same window. Select all (⌘+a), and then select File > Export Selected Images… > Expand Options > uncheck the Alpha checkbox > Choose (your destination folder)
Done! All your images are now exported with the alpha channel stripped off.
To remove alpha channel from png:
on Mac:
Preview version 9.0 (macOS Sierra) can remove the alpha channel if you export or save the image.
Preview version 10.0 (944.2) (macOS High Sierra) does not remove the alpha channel.
Both Export and/or Save does not remove the alpha channel from the image.
Well, since you're on a Mac, next time you probably just want to use Automator. Convert the image to BMP (lossless) and back to PNG. Let it save and voila...
I put Nikita Pushkar's very nice solution into a shell script that converts all iOS icons found in res/icon/ios:
It uses brew to install imagemagick if not available, so I guess it will run only on Mac.
#! /usr/bin/env bash
#
# remove alpha channel from PNG images when App Store upload fails
#
# taken from https://stackoverflow.com/a/52962485 - #Nikita Pushkar
#
# make sure to have brew installed, see https://brew.sh:
# /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
#
# make sure to have imagemagick installed, see https://imagemagick.org:
# brew install imagemagick
#
if command -v convert; then
echo "imagemagick seems to be installed"
else
echo "imagemagick not installed, trying to install ..."
if command -v brew; then
echo "brew is installed, using it"
else
echo "brew not installed, trying to install ..."
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
brew install imagemagick
fi
for i in `ls res/icon/ios/*.png`;
do
echo "convert $i"
convert $i -background white -alpha remove -alpha off $i;
done
I've used a tool (anyone that allows to convert images to any format from any format). Here are the steps:
1. Transform all png images to jpeg
2. Transform the jpeg images back to png.
Try to upload a new build.

Resources