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

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:

Related

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.

Imagemagick Batch operation conditional on Filesize - How?

I'm running Imagemagick on a command line Ubuntu terminal in Windows 10 - using the built in facility in Windows 10 - the Ubuntu App.
I am a complete linux novice but have installed imagemagick in the above environment.
My task - Auto remove the black(ish) border and deskew the images of thousands of scanned 35mm slides.
I can successfully run commands such as
mogrify -fuzz 35% -deskew 80% -trim +repage *.tif
The problem is:-
The border is not crisply defined nor is completely black, hence the -fuzz. Some images are over-trimmed at a certain fuzz, while others are not trimmed enough.
So what I want to do is to have two passes at this, with different fuzz %, for these reasons:-
1st pass with a low Fuzz%. Many images will not be trimmed at all but I have found that the ones that are susceptible to over-trimming will trim Ok with low %
Since all the images start with an identical filesize, the ones that have trimmed Ok will have a lower filesize (note these are tifs not jpgs)
So what I need to do is set a file size condition for the second pass at higher fuzz% THAT IGNORES file sizes below a certain value and does not perform any operation.
In this way, with few errors, all the images will be trimmed correctly.
So the question
- How can I adjust the command line to have 2 passes and to ignore a lower file size on the second pass?
I have a horrible feeling the the answer will be a script. I have no idea how to construct or set up Ubuntu to run this so if so, please can you point me to help for that also!!
In ImageMagick, you could do something like the following:
Get the input filesize
Use convert to deskew and trim.
Then find the new file
Then compare the new to the old to compute the percentdifference to some percent threshold
If the percent difference is less than some threshold, then the processing did not trim enough
So reprocess with a higher fuzz value and write over the input; otherwise keep the first one only and do not write over the old one.
Unix syntax.
Choose two fuzz values
Choose a percent change threshold
Create a new empty directory to hold the output (results)
cd
cd desktop/Originals
fuzz1=20
fuzz2=40
threshpct=10
list=`ls`
for img in $list; do
filesize=`convert -ping $img -precision 16 -format "%b" info: | sed 's/[B]*$//'`
echo "filesize=$filesize"
convert $img -background black -deskew 40% -fuzz $fuzz1% ../results/$img
newfilesize=`convert -ping ../results/$img -precision 16 -format "%b" info: | sed 's/[B]*$//'`
test=`convert xc: -format "%[fx:100*($filesize-$newfilesize)/$filesize<$threshpct?1:0]" info:`
echo "newfilesize=$newfilesize; test=$test;"
[ $test -eq 1 ] && convert $img -background black -deskew 40% -fuzz $fuzz2% ../results/$img
done
The issue is that you need to be sure you set your TIFF compression for the output the same as for the input so that the file sizes are equivalent and presumably the new size is not larger than the old one as happens with JPG.
Note that the sed is used to remove the letter B (bytes) from the file size, so they can be compared as numerals and not strings. The -precision 16 forces "%b" to report as B and not KB or MB.

How to crop AI (PDF embedded) to PNG using Ghostscript?

I've read a number of post and tried to follow but it's not working.
Using GS (gsdll32.dll) with the following arguments:
Info from bbox
%%BoundingBox: 33 244 577 546 %%HiResBoundingBox: 33.611976 244.201633
576.009896 545.351819
render and crop AI2PNG
-P-
-dNOPAUSE
-dBATCH
-dSAFER
-q
-IC:/Program Files (x86)/Gerber Scientific Products/OMEGA 6.50/Software/gs/fonts;C:/Program Files (x86)/Gerber Scientific Products/OMEGA 6.50/Software/gs/lib;C:/Program Files (x86)/Gerber
Scientific Products/OMEGA 6.50/Software/gs/resource
-sDEVICE=pngalpha
-g544x302
-c <> setpagedevice
-sOutputFile=E:/Images/AI from PLM/captain-america [Converted].png E:/Images/AI from PLM/captain-america [Converted].ai
Without any cropping logic I get the image on an 8.5 x 11, with cropping(above commands) the objects are translated mostly off the top of the page and do not seem to move to the left.
The size of the result image is correct.
Does anyone see anything wrong?
Thanks
You've put the /Install after the input file, that means it will be executed after the input file is complete. Which means it takes effect after the input is completely processed, which is too late to have nay effect.
Order of switches, and particularly order of input, is important in Ghostscript.
That's assuming that 'AI2PNG' is a synonym for Ghostscript.

Creating new eng.tessdata file for custom font in Tesseract giving error

Converted the PDF file into .tiff which is pretty straightforward
convert -depth 4 -density 300 -background white +matte eng.arial.pdf eng.arial.tiff
Then train tesseract for the .tiff file -
tesseract eng.arial.tiff eng.arial batch.nochop makebox
Then feed the .tiff file into tesseract -
tesseract eng.arial.tiff eng.arial.box nobatch box.train .stderr
Detect the Character set used -
unicharset_extractor *.box
But I am getting this error -
unicharset_extractor:./.libs/lt-unicharset_extractor.c:233: FATAL: couldn't find unicharset_extractor.
And it also happening for mftraining and combine_tessdata as well.
UPDATE
Ran unicharset_extractor on single box file and still doesn't work.
And it is not only with this command but also with mftraining, cntraining and combine_tessdata.

Determine bit depth of bmp file on os x

How can I determine the bit depth of a bmp file on Mac OS X? In particular, I want to check if a bmp file is a true 24 bit file, or if it is being saved as a greyscale (i.e. 8 bit) image. I have a black-and-white image which I think I have forced to be 24 bit (using convert -type TrueColor), but Imagemagick gives conflicting results:
> identify -verbose hiBW24.bmp
...
Type: Grayscale
Base type: Grayscale
Endianess: Undefined
Colorspace: Gray
> identify -debug coder hiBW24.bmp
...
Bits per pixel: 24
A number of other command-line utilities are no help, it seems:
> file hi.bmp
hi.bmp: data
> exiv2 hiBW24.bmp
File name : hiBW24.bmp
File size : 286338 Bytes
MIME type : image/x-ms-bmp
Image size : 200 x 477
hiBW24.bmp: No Exif data found in the file
> mediainfo -f hi.bmp
...[nothing useful]
If you want a commend-line utility try sips (do not forget to read the manpage with man sips). Example:
*terminal input*
sips -g all /Users/hg/Pictures/2012/03/14/QRCodeA.bmp
*output is:*
/Users/hg/Pictures/2012/03/14/QRCodeA.bmp
pixelWidth: 150
pixelHeight: 143
typeIdentifier: com.microsoft.bmp
format: bmp
formatOptions: default
dpiWidth: 96.000
dpiHeight: 96.000
samplesPerPixel: 3
bitsPerSample: 8
hasAlpha: no
space: RGB
I think the result contains the values you are after.
Another way is to open the image with the previewer preview.app and the open the info panel.
One of the most informative programs (but not easy to use) is exiftool by Phil Harvey http://www.sno.phy.queensu.ca/~phil/exiftool/ , which also works very well on MacOSX for a lot of file formats but maybe an overkill for your purpose.
I did this to investigate:
# create a black-to-white gradient and save as a BMP, then `identify` it to a file `unlim`
convert -size 256x256 gradient:black-white a.bmp
identify -verbose a.bmp > unlim
# create another black-to-white gradient but force 256 colours, then `identify` to a second file `256`
convert -size 256x256 gradient:black-white -colors 256 a.bmp
identify -verbose a.bmp > 256
# Now look at difference
opendiff unlim 256
And the difference is that the -colors 256 image has a palette in the header and has a Class:PseudoClass whereas the other has Class:Direct

Resources