imagemagick convert -contrast-stretch doesn't work after update to 6.9.x and up - imagemagick-convert

I use convert to process my scans. I use convert as follows:
convert in.tiff +dither -colors 2 -colorspace gray -contrast-stretch 0 out.tiff
The input file is about 8.5MBytes. In V6.8.9-9 the output size is about 1.1MBytes. In 7.0.8-14 the output size stays at 8.5MBytes.
I have searched for problems with -contrast-stretchbut I couldn't find info on my topic. The same problem occurs with the -threshold option. With the old version size gets smaller with the new version size doesn't decrease.
This is on ubuntu 18.04 libtiff-tools is installed. Old Version is on ubuntu 16.04.
Am I missing something?
Regards
Thommy

I found a solution. With identify -verbose out.tif I saw that depth differed. With the new version it is 8/1-bit in the old version it is 1-bit. Searching on that topic I found that -depth 1 could be the solution. And indeed adding -depth 1 to the command line solved my problem.
Still I don't know why the old version worked w/o it. But I am back to what I want.
Thommy

Related

Basic ImageMagic disconnect: converting plain ASCII.txt file into image file ASCII.jpg - ending up with errors

I have been trying to convert a plain text file (containing ASCII sentences / lines) into an JPEG image - not caring about any formats or styles - just a first try - keen on quick results:
After half a day trials and errors in all variations - all failing with the below (or similar) errors - and nearly going mad I have solved the following error message :
...
convert-im6.q16: not authorized `#a.txt' # error/property.c/InterpretImageProperties/3516.
I have gotten the wanted result when I have deactivitated
/etc/ImageMagick-6/policy.xml
into
/etc/ImageMagick-6/_policy.xml
Can somebody explain - please - what the magic behind is with this (deactivated) file ???
And please - being sure this file should become re-activated as it is by default - what do I need to change instead (in the file ???)
Thanks in advance with BR
If you are not on a shared server, you can edit your ImageMagick policy.xml file to give read|write permissions for the use of "#".
I suspect the defaults are still "none" for the use of "#" even if you disable the policy.xml file.
Then you can read a text file (in this case ipsum_lorem.txt) :
convert -size 1000x -font arial -pointsize 28 caption:"#ipsum_lorem.txt" x.jpg
or
cat ipsum_lorem.txt | convert -size 1000x -font arial -pointsize 28 caption:"#-" x.jpg
and the result should be:

Image Conversion - RAW to png/raw for game (Pac The Man X)

So I have raw image and I am just curious If I can edit such image to save as RGB-32 Packed transparent interlaced raw and what program I could use, there is specification:
Format of RAW image
I have tried using photoshop but then game crashes. Is it even possible? I should get file without thumbnail. I also tried using gimp, free converters and Raw viewer but no luck. Any suggestions?
Edit:
Used photoshop (interleaved with transparency format), game starts but images are just bunch of pixels.
file that i try to prepare (221bits)
We are still not getting a handle on what output format you are really trying to achieve. Let's try generating a file from scratch, to see if we can get there.
So, let's just use simple commands that are available on a Mac and generate some test images from first principles. Start with exactly the same ghost.raw image you shared in your question. We will take the first 12 bytes as the header, and then generate a file full of red pixels and see if that works:
# Grab first 12 bytes from "ghost.raw" and start a new file "red.raw"
head -c 12 ghost.raw > red.raw
# Now generate 512x108 pixels, where red=ff, green=00, blue=01, alpha=fe and append to "red.raw"
perl -E 'say "ff0001fe" x (512*108)' | xxd -r -p >> red.raw
So you can try using red.raw in place of ghost.raw and tell me what happens.
Now try generating a blue file just the same:
# Grab first 12 bytes from "ghost.raw" and start a new file "blue.raw"
head -c 12 ghost.raw > blue.raw
# Now generate 512x108 pixels, where red=00, green=01, blue=ff, alpha=fe and append to "blue.raw"
perl -E 'say "0001fffe" x (512*108)' | xxd -r -p >> blue.raw
And then try blue.raw.
Original Answer
AFAIK, your image is actually 512 pixels wide by 108 pixels tall in RGBA8888 format with a 12-byte header at the start - making 12 + 4*(512 * 108) bytes.
You can convert it to PNG or JPEG with ImageMagick like this:
magick -size 512x108+12 -depth 8 RGBA:ghost.raw result.png
I still don't understand from your question or comments what format you actually want - so if you clarify that, I am hopeful we can get you answered.
Try using online converters. They help most of the time.\
A Website like these can possibly help:
https://www.freeconvert.com/raw-to-png
https://cloudconvert.com/raw-to-png
https://www.zamzar.com/convert/raw-to-png/
Some are specific websites which ask you for detail and some are straight forward conversions.

cygwin file not found on network windows drive, possible issue with spaces

to try and not over complicate my issue i'm using cygwin and have two windows computers on a network sharing data. i'm trying to add a logo to some photos and are having a tough time with finding the logo file with cygwin in this code
for f in *.jpg; do
convert "$f" \
-gravity southeast \
-draw 'image over 0,0 0,0 "//deepfrogphotopc/L Xotio Passport/temp/logo2.png"' \
-write //deepfrogphotopc/L Xotio Passport/temp/og-rotate-logo/"$f" \
-resize 1200x1200 \
//deepfrogphotopc/L Xotio Passport/temp/1200px/"$f"
done
I have no problem when using cd to get to this location with cygwin
//deepfrogphotopc/L Xotio Passport/temp/
but then when using the above loop to watermark the files cygwin can't find the logo file and I assume it won't write to the correct directories after either because of the same problem. I actually got it working using
../logo2.png
but really want to use the actual address like I'm trying. Any help with this is very much appreciated!

jpg won't optimize (jpegtran, jpegoptim)

I have an image and it's a jpg.
I tried running through jpegtran with the following command:
$ jpegtran -copy none -optimize image.jpg > out.jpg
The file outputs, but the image seems un-modified (no size change)
I tried jpegoptim:
$ jpegoptim image.jpg
image.jpg 4475x2984 24bit P JFIF [OK] 1679488 --> 1679488 bytes (0.00%), skipped.
I get the same results when I use --force with jpegoptim except it reports that it's optimized but there is no change in file size
Here is the image in question: http://i.imgur.com/NAuigj0.jpg
But I can't seem to get it to work with any other jpegs I have either (only tried a couple though).
Am I doing something wrong?
I downloaded your image from imgur, but the size is 189,056 bytes. Is it possible that imgur did something to your image?
Anyway, I managed to optimize it to 165,920 bytes using Leanify (I'm the author) and it's lossless.

Is it possible using the PHP5 imagick wrapper?

I don't have possibility to run convert via cmdline and the only way to use Imagick is via the PHP5 wrapper. I would need to run following command:
convert in.jpg -channel RGB -auto-level +level-colors red,white out.jpg
Unfortunately I haven't found in documentation any method that would perform any of these options. Can somebody with better knowledge of the php wrapper help?
I found only Imagick::levelImage() but couldn't simulate -auto-level and level-colors is nowhere to be found.
Thanks for help
In the end I got help on imagemagick forum, so for anybody with similar problem, here is what worked for me.
$img = new Imagick('in.jpg');
// grayscale image
$img->modulateImage(100, 0, 100);
// instead of auto-level option, where 65535 = Imagick::getQuantumRange()
$img->contrastStretchImage (0, 65535, Imagick::CHANNEL_ALL);
// instead of missing level-colors option, apply clut with the 2 desired colors
$clut = new Imagick();
$clut->newPseudoImage(1, 2, "gradient:red-white");
$img->clutImage($clut);
$img->writeImage('out.jpg');
For more info you can read the imagemagick thread

Resources