Change mode of an image from indexed to rgb using shell - image

I'd like to make a script where I could put an image file(in indexed mode) as input then the return will be one image (in rgb mode).
It is like something gimp does in the interactive mode when you you click on Image -> Mode then click on rgb (http://docs.gimp.org/en/images/tutorials/quickie-mode-menu.png), I want to do the same thing but in the linux terminal (or in python) with a lot of images every day.
Any tips?
Thanks in Advance, sorry for the bad english.

This would be done easier/faster with ImageMagick.
Then you would be able to run the following command from your shell:
$ convert cmyk_image.jpg -colorspace rgb rgb_image.jpg
A guide/reference is available at the ImageMagick project wiki.

I tried :
$ convert indexed_image.tif -colorspace rgb rgb_image.tif
This is TIFF with an indexed table RGB, but the result colors are slightly different (darker and more intense).
E.g. table entry 58 which is 192 248 200 (light green) transforms into 134 239 147 (darker green).

Related

File too big when converting pdf to jpg using ImageMagick/Ghostscript

I'm trying to have an identical output to what Adobe Acrobat does with File>>Save As>>Image>>JPEG. But whenever I use ImageMagick's convert it takes much longer and the resulting file is 2-3x bigger. I set the density option to -density 686 because that was the density of Acrobat's output according to the following:
Here is the result of convert (filename changed to Bitter_Creek.jpg), not sure why it says aspect ratio and the dimensions will still differ even when setting the size option to -size 14859x18388
Using the ls -l command to describe the resulting JPGs I get this:
(top file is result of ImageMagick's convert and the bottom file is result of Acrobat's Save As:
I would like to know which options to use to get an identical output.
Filesize of a jpeg image depends on quality setting. The default setting of Acrobat is "Medium" whose quality value is considerably low (62), whereas ImageMagick's convert is defaulted to higher value.
If you expect the equivalent result, add -quality 62 option to convert, although picture quality will be accordingly degraded.

Warning: Input PNG does not have an 8 bit input depth. Please convert your PNG to 8-bit for optimal performance on iPhone OS

I started using the ionicons_2-0-1_ios-pause-outline and
http://fa2png.io/r/ionicons/
to convert these to the correct size.
However when I try the iOS iPhone 7 simulator I get this message:
Warning: Input PNG does not have an 8 bit input depth. Please convert
your PNG to 8-bit for optimal performance on iPhone OS
How can I convert icons to png with the correct depth?
Your images are not in 8-bit, images need to be in 8-bit, not 16-bit.
That goes for the icon as well. and iOS only supports 8-bit images as well.
8-bit means 8-bits per color channel, which is 16.7 million colors.
16 bits per channel give 32,769 colors per channel, which is actually 281 trillion possible colors! 16-bit is only used for photo editing,
images still need to be saved back down to 8-bit for printing.
MakeAppIcon is useful website for generating App icons. and IcoFX is a fantastic tool for creating 8-bit depth icon.
The main difference between an 8 bit image and a 16 bit image is the amount of tones available for a given color. So your image has too many colors in it. Here's a list of some applications that can solve this problem for you. http://myappmag.com/make-windows-icons/ from that list; Number 5 seems to be a good option.
Also this can help you find a color within the 8-bit range.
http://neildowning.com/HEX_to_RGB_color_converter.php
Looks like Xamarin requires 8-bit per color channel
(8-bit for Red, 8-bit for Green, and 8-bit for Blue)
http://forums.gamesalad.com/discussion/comment/61399/#Comment_61399
That is called "true color" which is actually PNG-24 (because 24 = 8*3)
https://en.wikipedia.org/wiki/Color_depth#True_color_.2824-bit.29
So why don't we run a python script to do that for us.
If you are not familiar with python, all you need to do is
Download Python (make sure you add pip to your path during setup)
run pip install pillow in the cmd (Run as Administrator if says Access is denied)
. Pillow is an imaging library for python.
Make a file in the folder with your images, call it convert.py
Put the following in it
def convert_to_24(image_file):
from PIL import Image
try:
im = Image.open(image_file)
except(FileNotFoundError):
print(image_file ,"was not found.")
return
print(image_file,"is in",im.mode,"mode.")
if im.mode != "RGB":
im = im.convert("RGB")
im.save(image_file.split('.')[0]+"_24.png")
return
if __name__ == "__main__":
convert_to_24(input('Enter image file name:'))
Open cmd where the script and the images are and type python convert.py
When it asks for the file name, put the file name including the extension, like filename.png
It will tell you in what mode the image was, and will create another image with a name filename_24.png that has 8-bit color pixels (aka 24bit png).
How can I convert icons to png with the correct depth?
Convert to jpg and back to png. That will also remove the alpha (transparency) channel.

Add background to bitonal djvu file

I have a few black and white djvu files that I would like to add a few different background images to at random. This is to make it seem more book like and I think looks better.
Using the command line I can extract each image and then write some code to add the background however this bloats the file a lot because of duplication. I would like to add the background to the file once and then include it using the INCL chunk for the other pages. However it is very confusing how to do this through the DjvuLibre command set.
The current djvu file also has a text layer that I would like to extract and then reapply.
I wrote some code to automate the steps here.
Which are listed below:
In order to successfully add a background image to a foreground image, I have to follow these steps (using a DOS Cmd window):
1- extract the bitomal RLE image from the Djvu File
ddjvu -format=rle -v myfile.djvu temp.rle
2- extract (or create) the background image. Be sure that the size of this image is equal or greater than the foreground image in order to have, after a reduction a integer:
e.g. I have a 2592 x 3508 300dpi foreground image, and I want a background image of 100dpi. So I create a 2592] x 3510 100dpi image (I added 2 pixels to the height in order to have 2594 modulo 3=0).
After a 1/3 resampling, I have a 864 x 1170 image.
3- (do something with this background image) and save it as myfile.ppm (24 bits per pixel)
4- join into an unique file the 2 images:
copy /b myfile.rle + myfile.ppm myfile.mix (using a brave old DOS command)
5- encode the new page into a DjVu file:
csepdjvu -vv -d 300 myfile.mix myNewFile.DjVu
Bingo: It works!!!

Divide large image into A4 sized images

I would like to split a large PNG file into A4 pages so they can be printed out easily.
I would like to use a Linux command line script to do this:
shell> split-into-a4-sized-pages some-big.png
I assume you have ImageMagick & pdfposter installed.
A) convert your .png to .pdf (using ImageMagick)
convert input0.png input1.pdf
B) tile your image using pdfposter:
pdfposter -s4 input1.pdf out.pdf
this command enlarges input0 exactly 4 times, print on the default A4
media, and let pdfposter determine the number of pages required.
Try using imagemagick's crop to your desired size.
Say you have a 640x962 image:
and you want to crop it into 4 320x481 images:
Use:
convert pexels-adonyi-gábor-1400172.jpg -crop 240x240+0+0 cropped.jpg
convert pexels-adonyi-gábor-1400172.jpg -crop 320x481+320+0 cropped.jpg
convert pexels-adonyi-gábor-1400172.jpg -crop 320x481+0+481 cropped.jpg
convert pexels-adonyi-gábor-1400172.jpg -crop 320x481+320+481 cropped.jpg
Now you'd have to find out how many pixels fit into an A4 page in your printer, and the dimensions of the image, and it is a very simple script from here.
Photo by Adonyi Gábor from Pexels.
You can use convert of ImageMagick to scale the image; there are probably other tools in ImageMagick to clip the image if you want.
I don't know of any ready-made command line tool to do this. Unless you use it all the time, ImageMagick may take longer to figure out the right combination of commands and options, than to write a quickie program.
An easy way, if you know Python at all, is write a few-line program using PIL (Python Imaging Library). To read an image takes one line. To extract chunks of some width and height at specified location to save as new image files, is also easy. Add a couple for loops to scan rows and columns of A4-sized chunks, and you're done.
If you don't know Python, just about all quick-to-write programming languages have a similar capability. The GD library comes to mind; it has bindings for several languages.
NetPBM's pamdice will do the splitting into multiple pages. You'll have to set the -width and -height options according to the DPI of your desired A4 images.
And you'll also have to convert the input image to netpbm format first with pngtopam:
pngtopam big.png | pamdice -outstem tile -height h -width w
That will leave you will a bunch of files called tile_x_y.ppm
Convert each one of those to PNG with pnmtopng

JPEG Shows in Firefox but Not IE8

I'm working on a Sidebar Gadget and cannot get my JPEGs to show up (PNGs work). When I try to open the file by itself in IE8 it doesn't work. Firefox, of course, can open it fine.
JPEG Details:
Dimensions: 1080X900
180 dpi
Bit depth 24
Color representation: uncalibrated
I've found some things talking about the images being compressed incorrectly (?) but I haven't been able to get it working...
Any clues?
IE8 drops support for CMYK JPEG and renders them as the infamous red X without so much as a warning.
If you have ImageMagick:
identify -verbose image.jpg
will show you the image colorspace. If it's CMYK, you can convert to RGB with:
convert broken.jpg -colorspace RGB fixed.jpg
If you need to do CMYK to RGB conversion on a whole batch of JPEG-images, this command may be helpful to you:
for i in *.jpg; do convert "$i" -colorspace RGB "$i"; done
PS: If you'd like to see what is going on, just add -verbose:
for i in *.jpg; do convert "$i" -colorspace RGB -verbose "$i"; done
I had a similar issue with IE8 not displaying two JPEG images. FF, Safari, Chrome all displayed them without complaint but IE acted as if the files were not there. I have no idea what was going on, but a quick image conversion to gif or png fixed the problem. Just another in a long line of confirmations that IE sucks.
Had similar problems with existing images, which will not show up in IE8.
Problem is, as converter42 says: CMYK-Images
Convert them to RGB colorspace and all is good
The Solution with the PNG is not the best, because PNG files can be MUUUCH larger than JPGS.
If you are using photoshop for creating the jpgs. Try the below.
Open the file and go to 'Image' menu
Go to Mode
Select RGB
Save and upload to server.
This should work.
Why are you dealing with the image at 180 dpi and not the 72dpi screen resolution? At screen resolution the image will be roughly double that size. Still, the size is manageable for any browser.
When creating a gadget, you should be using PNGs for all the elements of the gadgets. Are you having issues displaying JPEG photos?
Have you looked for the yellow bar at the top of IE that blocks certain suspicious content from being loaded (popups, activex, javascript, etc.)? If it appears, try telling it to "allow".
Lastly, what are you using to compress your images to JPEG?
EDIT: If you want to do batch conversion use the batch converter in photoshop or use the Actions panel to record the conversion process for a single image, then replay the action on an entire folder. Additionally, you can save this action to a "droplet" which is a small application containing the action that you can drop an image or folder on top to.
Alternatively, if you don't fell like learning Actions, XNView is an excellent image viewer and converter that supports something like 160 different image formats and can batch convert and batch rename huge lists of files.
I fixed this issue by opening the CMYK JPEG file in Windows Paint and then saving as a JPEG, which Paint encodes as RGB by default. Not a great solution because I'm sure that Paint's converter is not as robust as Photoshop's, but this can be a quick fix if the job needs to be done now and there's no access to the tools above.

Resources