what I want is to add eps file into temporary ps file which has text written, then I convert my ps file to eps file using ghostscript, but when I see my eps file in AI outline mode, I see extra square around my eps file which is size box, which should not be there, It should be part of single compound box
Ghostscript version is 9.05 and before I include eps into ps I need to resize it. So resized eps file shows page border into outline mode. Which is actually not there, but when it goes to machine it will cut out that path which should not be case.
Alright, I think I have some understanding of what you're doing and where the trouble may be creeping in. As I commented, you're running the file through ghostscript multiple times. Each time it has to interpret the postscript code and construct an internal display-list representation and then recreate appropriate postscript code on the output end. So it's the clone of a clone of a clone problem. Any little hiccup can cause cascade failures.
So, enough of being preachy. The alternative is to manipulate the eps file as text.
So, if we want the image to be scaled to fill a 500x500 square, we will be guided by the number in the BoundingBox comment. I'll quote this silly file from the linked question as an example:
%!PS-Adobe-2.0 EPSF-2.0
%%BoundingBox: 72 700 127 708 %<-- modify this
%%HiResBoundingBox: 72.000000 700.000000 127.000000 707.500000 %<-- delete this
%%EndComments
% EPSF created by ps2eps 1.68
%%BeginProlog
save
countdictstack
mark
newpath
/showpage {} def
/setpagedevice {pop} def
%%EndProlog
%%Page 1 1 %<-- insert translate and scale after this line
/Times-Roman findfont
11 scalefont setfont
72 700 moveto
(This is a test)show
%%Trailer
cleartomark
countdictstack
exch sub { end } repeat
restore
%%EOF
So, the BoundingBox was %%BoundingBox: 72 700 127 708 and it needs to be 0 0 500 500 or rather (to preserve the aspect ratio) 0 0 x 500 or 0 0 500 y where x or y (whichever it happens to be) is < 500. The existing size is 127-72 x 708 - 700 = 55 x 8. So our scaling factor is 500/55. But we also want to translate the lower-left corner to the origin, and its simplest to do that first, so the scaling doesn't affect the interpretation of the numbers.
So, to take 72 700 127 708 to 0 0 500 y, first we add -72 -700 translate to the file, and modify the bounding box to 0 0 55 8, and delete that silly HiRes line: we don't really need it.
Then, we add 500 55 div dup scale (let the interpreter do the math, hee hee). So the maximum x will now be 500, but, oh, what to put for the y? A quick calculation yields 72!
So, this awk program will modify an eps file to be 500 points wide, with y scaled appropriately.
/%%BoundingBox: ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*)/{x=$2;y=$3;w=$4-x;h=$5-y;print $1,0,0,500,(500/w)*h}
!/%%BoundingBox:/&&!/%%HiRes/{print}
/%%Page /{print -x,-y,"translate"; print 500,w,"div dup scale"}
Usage:
$ awk -f epsscale.awk etest.eps
Related
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.
Hello friends,
I have a hard time to ocr the above image due to the gaps that were made due to line removal.So could anyone kindly guide me on how to fill the gaps in chinese character using imagemagick
Cool question! There are many ways of approaching this but unfortunately I can't tell which ones work! So I'll give you some code and you can experiment by changing it around.
For the moment, I tried simply removing any lines that have white pixels in them, but you could look at the lines above and below, or do something else.
#!/bin/bash -xv
# Get lines containing white pixels
convert chinese.gif -colorspace gray -threshold 80% DEBUG-white-lines.png
# Develop that idea and get the line numbers in an array
wl=( $(convert chinese.gif -colorspace gray -threshold 80% -resize 1x\! -threshold 20% txt: | awk -F '[,:]' '/FFFFFF/{print $2}') )
# White lines are:
echo "${wl[#]}"
# Build a string of a whole load of "chop" commands to apply in one go, rather than applying one-at-a-time and saving/re-loading
# As we chop each line, the remaining lines move up, changing their offset by one line - UGHH. Apply a correction!
chop=""
correction=0
for line in "${wl[#]}" ; do
((y=line-correction))
chop="$chop -chop 0x1+0+$y "
((correction=correction+1))
done
echo $chop
convert chinese.gif $chop result.png
Here's the image DEBUG-white-lines.png:
The white lines are identified as:
44 74 134 164 194 254 284 314 374 404
The final command run is:
convert chinese.gif -chop 0x1+0+44 -chop 0x1+0+73 -chop 0x1+0+132 -chop 0x1+0+161 -chop 0x1+0+190 -chop 0x1+0+249 -chop 0x1+0+278 -chop 0x1+0+307 -chop 0x1+0+366 -chop 0x1+0+395 result.png
If I understand this correctly then you want to find a way of removing the white lines and then still get it to go through an OCR?
The best way would be by eye and connect the dots so to speak so the last pixel of the characters line up.
A programitcal way would be to remove the white line ad then duplicate the line above (or below) and shift it into place.
康 家 月 而 视 , 喝 道
" 你 想 做 什 么 !"
秦 微 微 一 笑 , 轻 声 道
不 知 道 看 着 些 亲 死 眼 前 ,
前 辈 会 不 会 有 痛 的 感 觉 。"
说 , 伸 手 一 指 , 一 位 少 妇
身 形 一 顿 , 小 出 现 了 一 个 血 洞
倒 地 身 广 。
康 家 相 又 惊 又 , 痛 声 道
I don't read Chinese but this is what it got machine translated as
Kang Jia month and watch, drink
"What do you want to do !"
Qin Weiwei smiled, softly
I don't know. look at some dead eyes. ,
Predecessors will not feel pain ."
And said, stretch out a finger , a young woman.
In The Shape of a meal, a small blood hole appeared
Down to the ground wide.
The Kang family was shocked and sore
Can anyone confirm the following behaviour on MacOS 10.13 High Sierra with GhostScript? I don't get the problem when using 10.12 Sierra.
When I create PDFs in GhostScript, it always leaves the Title, Author and other metadata blank.
I know that you can set the metadata with PDFmarks within the PostScript file itself (or a secondary merged PS file that just contains PDFmarks), but that requires manually setting the field for each file.
Currently, my PDFs fail PDF-X validation until I manually add the metadata.
My PostScript does contain DSC comments, and the GS documentation implies that this should be picked up, as ParseDSCCommentsForDocInfo is true by default.
/usr/local/bin/gs \
-dPDFX \
-dNOPAUSE \
-dBATCH \
-sDEVICE=pdfwrite \
-sOutputFile="$filename" \
-dProcessColorModel=/DeviceCMYK \
-dCompatibilityLevel=1.4 \
"$f" \
/Library/PostScript/PDFX_def.ps
The source of the PostScript does not seem to be a factor: Adobe apps like InDesign, MacOS's cgpdftops, all behave similarly.
Here's a simple test PS file. Distiller takes the comments and uses them for DocInfo; GhostScript doesn't on MacOS 10.13.
%!PS-Adobe-3.0
%%Title: (MyTitle.file)
%%Creator: (MyApp: cgpdftops CUPS filter)
%%CreationDate: (Saturday, February 03 2018 10:19:01 GMT)
%%For: (User Me)
%%BoundingBox: 36 36 576 756
%%Pages: 1
%%LanguageLevel: 2
%%EndComments
%%BeginSetup
% this is where fonts would be embedded
%%EndSetup
%%Page: (1) 1
%%BeginPageSetup
% this is where page-specific features would be specified
%%EndPageSetup
% Draw a black box around the page
0 setgray
1 setlinewidth
36 36 540 720 rectstroke
% Draw a two inch blue circle in the middle of the page
0 0 1 setrgbcolor
306 396 144 0 360 arc closepath fill
% Draw two half inch yellow circles for eyes
1 1 0 setrgbcolor
252 432 36 0 360 arc closepath fill
360 432 36 0 360 arc closepath fill
% Draw the smile
1 setlinecap
18 setlinewidth
306 396 99 200 340 arc stroke
% Print it!
showpage
%%EOF
As of MacOS Mojave 10.14.3 and GhostScript version 9.26, this now fixed. I can only presume it was a bug in GhostScript or MacOS.
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.
I am using wkhtmltopdf to generate a PDF file that is going to a printer and have some troubles with making the content fill up an entire page in the resulting PDF.
In the CSS I've set the width and height to 2480 X 3508 pixels (a4 300 dpi) and when creating the PDF I use 0 for margins but still end up with a small white border to the right and bottom. Also tried to use mm and percentage but with the same result.
I'd need someone to please provide an example on how to style the HTML and what options to use at command line so that the resulting PDF pages fill out the entire background. One way might be to include bleeding (this might be necessary anyway) but any tips are welcome. At the moment I am creating one big HTML page (without CSS page breaks - might help?) but if needed it would be fine to generate each page separately and then feed them all to wkhtmltopdf.
wkhtmltopdf v 0.11.0 rc2
What ended up working:
wkhtmltopdf --margin-top 0 --margin-bottom 0 --margin-left 0 --margin-right 0 <url> <output>
shortens to
wkhtmltopdf -T 0 -B 0 -L 0 -R 0 <url> <output>
Using html from stdin (Note dash)
echo "<h1>Testing Some Html</h2>" | wkhtmltopdf -T 0 -B 0 -L 0 -R 0 - <output>
Using html from stdin to stdout
echo "Testing Some Html" | wkhtmltopdf -T 0 -B 0 -L 0 -R 0 - test.pdf
echo "Testing Some Html" | wkhtmltopdf -T 0 -B 0 -L 0 -R 0 - - > test.pdf
What did not work:
Using --dpi
Using --page-width and --page-height
Using --zoom
We just solved the same problem by using the --disable-smart-shrinking option.
I realize this is old and cold, but just in case someone finds this and has the same/similar problem, here's a workaround that worked for me after some trial&error.
I created a simple filler.html as:
<!DOCTYPE html>
<html>
<head>
</head>
<body style="margin: 0; padding: 0;">
<div style="height: 30mm; background-color: #F7EBD4;">
</div>
</body>
</html>
Use valid HTML (!DOCTYPE is important) and only inline styles. Match the background color to that of the main document and use height equal or bigger than your margins.
I run version 0.12.0 with the following arguments:
wkhtmltopdf --print-media-type --orientation portrait --page-size A4
--encoding UTF-8 --T 10mm --B 10mm --L 0mm --R 0mm
--header-html filler.html --footer-html filler.html - - <file.html >file.pdf
Hoping this helps someone...
I'm using version 0.12.2.1 and setting:
body { padding: 0; margin 0; }
div.page-layout { height: 295.5mm; width: 209mm;}
worked for me.
Of course need to add 0 margins by:
wkhtmltopdf -T 0 -B 0 -L 0 -R 0
At http://code.google.com/p/wkhtmltopdf/issues/detail?id=359 I found out more people 'suffer' from this bug. The --dpi 300 workaround did not work for me, I had to set --zoom 1.045 to zoom in a bit which made the extra right and bottom border disappear...
Works fine for me with -B 0 -L 0 -R 0 -T 0 options and using your trick of setting up an A4 sized div.
Did you remember to use body {margin:0; padding:0;} in the top of your CSS?
I cannot help you with CSS page breaks as I have not trialled an errored those yet, however, you can run scripts on the page to do clever things. Here is a jQuery example of how to split content down into page size chunks based on the length of the content. If you can get that adapted to work with wkhtmltopdf then please post here!
http://www.script-tutorials.com/demos/79/index.html
What you are experiencing is a bug.
You'll need to set the --dpi option when converting the file. In you case you will probably want --dpi 300, but that can be set lower.
Solved it by increasing the DPI
I'm working with an A4 size in portrait mode. Had white space to the right.
I noticed that as the dpi is increased, the white space got thinner.
at 300 dpi the white space is not visible in chrome pdf view at (max) zoomed at 500%
In Adobe reader it's still visible. It got better at 600 DPI and at 1200 DPI it's become invisible even at 6500% zoom.
There's no disadvantage to this so far as I observed, all dpi generate the same file size and run at the same speed (tested on 1 page).
effectively my settings are as follows:
echo "<html style='padding=0;margin=0'><body style='background-color:black;padding=0;margin=0'></html>" | wkhtmltopdf -T 0 -B 0 -L 0 -R 0 --disable-smart-shrinking --orientation portrait --page-size A4 --dpi 1200 - happy.pdf
If using an unscaled PNG image (thus will be pixel perfect) the default ratio, for an A4 needs to be 120ppi thus # 210mm = 993 pixels wide x 1404 pixels high, if the source is 72 or 300 dpi it makes no difference for a default placement, its the 993 that's counted as 210 mm
No heights, no width, no stretch, nor shrink just default place image as background un-scaled.
wkhtmltopdf --enable-local-file-access -T "0mm" -L "0mm" -R "0mm" -B "0mm" test.html test.pdf
here is such an image reduced into A 4 pdf page 2 different densities same number of pixels
If you use scaling you can use different density values, but this is all that is needed by default's, since PDF works on overall pixel values not DPI as such. Note the PNG is actually smaller by insertion in a PDF than the source JPG which was over 372 KB