despite using the most simple boilerplate I can find, I can't seem to get graphviz to render a png image onto a node
Some may consider this a duplicate of How do I get DOT to display an image for a node? however this is the question I was following to get to this point and it STILL doesn't work
I've tried rendering already in several programs including vscode's preview extension, the dot -Tpng graph.png chickens2.dot -v command line method, and GVEdit and none of them correctly render the image into the node
here is my code
digraph graph1 {
node [shape=record];
white [image="dye_powder_white.png", label=""];
}
and the folder structure
Chickens/
|chickens2.dot
|dye_powder_white.png
I wanted it to simply show the icon inside of the node, but it just renders a blank node.
here is the output from dot.exe:
>dot -Tpng -o graph.png chickens2.dot -v
dot - graphviz version 2.38.0 (20140413.2041)
Using render: cairo:cairo
Using device: png:cairo:cairo
libdir = "C:\Program Files (x86)\Graphviz2.38\bin"
Activated plugin library: gvplugin_dot_layout.dll
Using layout: dot:dot_layout
The plugin configuration file:
C:\Program Files (x86)\Graphviz2.38\bin\config6
was successfully loaded.
render : cairo dot fig gd gdiplus map pic pov ps svg tk vml vrml xdot
layout : circo dot fdp neato nop nop1 nop2 osage patchwork sfdp twopi
textlayout : textlayout
device : bmp canon cmap cmapx cmapx_np dot emf emfplus eps fig gd gd2 gif gv imap imap_np ismap jpe jpeg jpg metafile pdf pic plain plain-ext png pov ps ps2 svg svgz tif tiff tk vml vmlz vrml wbmp xdot xdot1.2 xdot1.4
loadimage : (lib) bmp eps gd gd2 gif jpe jpeg jpg png ps svg
pack info:
mode undefined
size 0
flags 0
margin 8
pack info:
mode node
size 0
flags 0
fontname: "Times-Roman" resolved to: (ps:pango Times New Roman, ) (PangoCairoWin32Font) "Times New Roman, 13.9990234375"
network simplex: 1 nodes 0 edges maxiter=2147483647 balance=1
network simplex: 1 nodes 0 edges 0 iter 0.00 sec
Maxrank = 0, minrank = 0
mincross: pass 0 iter 0 trying 0 cur_cross 0 best_cross 0
mincross graph1: 0 crossings, 0.00 secs.
network simplex: 1 nodes 0 edges maxiter=2147483647 balance=2
network simplex: 1 nodes 0 edges 0 iter 0.00 sec
routesplines: 0 edges, 0 boxes 0.00 sec
Using render: cairo:cairo
Using device: png:cairo:cairo
dot: allocating a 19K cairo image surface (83 x 60 pixels)
gvRenderJobs graph1: 0.00 secs.
here is the exact png image I'm trying to embed just in case it's incompatible with graphviz and I don't realize:
https://mega.nz/#!M8EHEITJ!Mm489BA4sd5JLoeWlY7BM-YCIkHeAni96d-e1IY4UAQ
and finally, the resulting image which is the same in every method I've tried:
https://i.imgur.com/IcIJSMA.png
some things I'm considering:
is there some kind of configuration I'm not seeing which disables images by default?
do I have some kind of outdated version? (literally downloaded the stable this morning to try it out so I doubt it)
am I simply doing something wrong?
are graphviz images incompatible with windows 10?
am I missing a prerequisite library?
is my png image incompatible with graphviz somehow?
I've been trying this for an hour or so now and none of my attempts seem to be changing anything.
what is the correct way to get graphviz to render an image onto a node?
Old question, but I also couldn't figure this out. The attribute image doesn't seem to work as expected, and the manpage doesn't help, nor do the docs. Posting what worked for me for others who come across this question.
This answered it for me, from 2011. For example, in some image.gv file:
digraph {
ratio="fill";
size="10,10!";
margin="0,0";
node [shape=plain];
root [label=<<TABLE border="0"><TR><TD><IMG SRC="image.png"/></TD></TR>
<TR><TD>text under</TD></TR></TABLE>>];
}
Related
I followed the instructions here to change the default node shape: How to set default node shape to box instead of oval?
Input file:
digraph Blah {
rankdir="LR"
node [shape="box"];
A -> B -> C;
B -> D;
}
I then use the command dot -v -Txdot gt.dot > gt.xdot.
Output (verbose):
dot - graphviz version 2.44.0 ()
libdir = "/usr/lib/graphviz"
Activated plugin library: libgvplugin_core.so.6
Using render: xdot:core
Using device: xdot:xdot:core
Activated plugin library: libgvplugin_dot_layout.so.6
Using layout: dot:dot_layout
The plugin configuration file:
/usr/lib/graphviz/config6
was successfully loaded.
render : cairo dot dot_json fig json json0 map mp pic pov ps svg tk visio vml xdot xdot_json
layout : circo dot fdp neato nop nop1 nop2 osage patchwork sfdp twopi
textlayout : textlayout
device : canon cmap cmapx cmapx_np dot dot_json eps fig gv imap imap_np ismap json json0 mp pdf pic plain plain-ext png pov ps ps2 svg svgz tk vdx vml vmlz x11 xdot xdot1.2 xdot1.4 xdot_json xlib
loadimage : (lib) eps gif jpe jpeg jpg png ps svg
pack info:
mode undefined
size 0
flags 0
margin 8
pack info:
mode node
size 0
flags 0
fontname: "Times-Roman" resolved to: (ps:pango FreeSerif, REGULAR) (PangoCairoFcFont) "FreeSerif, Regular" /root/.fonts/FreeSerif.otf
Illegal instruction
But, when I remove the node [shape="box"]; line, it works. What am I doing wrong?
[this file worked correctly on my linux system with two versions of Graphviz]
You aren't doing anything wrong, but your font library info may be messed up?
/root/.fonts seems like a weird place for fonts.
What is the -v output when you use the default node shape? Does it still reference /root/.fonts?
I am trying to read and write jpegs wth Adobe RGB colorspace in OpenCV. OpenCV assumes the jpeg has sRGB colorspace and when displaying or writing to file, the image loses some of its color intensity. I found this intensity loss was due to colorspace difference by answers given to my previous question.
Is there anyway I can make OpenCV to read Adobe RGB colorspace without casting it to sRGB?
Some information that is hopefully useful for anyone looking for a work-around for dealing with ICC and other profiles...
You can see what profiles are present in an image using ImageMagick which is installed on most Linux distros and is available for macOS and Windows. In the Terminal, or Command Prompt on Windows, run:
magick identify -verbose frog.jpg | grep 'Profile-.*bytes'
Profile-icc: 578 bytes
That tells you this image has a 578 byte ICC profile embedded.
If you are on Windows and don't have grep, you can equally use the following, though you may need to double up the percent sign, or prefix it with a caret (^) or somehow escape it:
magick identify -format "%[profiles]" frog.jpg
icc
You can extract that profile from the image, using this command:
magick frog.jpg frog.icc
And, you'll get a 578 byte ICC profile:
ls -l *icc
-rw-r--r-- 1 mark staff 578 24 Apr 10:36 frog.icc
You can check that the profile looks correct using the file command:
file *icc
frog.icc: ColorSync color profile 2.1, type ADBE, RGB/XYZ-mntr device by ADBE, 560 bytes, 11-8-2000 19:51:59 "Adobe RGB (1998)"
You can apply that profile to some other file like this:
magick other.jpg -profile "icc:frog.icc" otherWithProfile.jpg
Once you have extracted the profile using the above method, you can apply it to an image that you plan to use with OpenCV using PIL/Pillow's ImageCMS Module.
For that, I think you need to use these steps or something very similar, though I have not tested it:
from PIL import Image, ImageCMS
import numpy as np
# Open frog with PIL/Pillow
im = Image.open('frog.jpg')
iccp = PIL.ImageCms.getOpenProfile("profile.icc")
rgbp = ImageCms.createProfile("sRGB")
icc2rgb = ImageCms.buildTransformFromOpenProfiles(rgbp, iccp, "RGB", "RGB")
result = ImageCms.applyTransform(im, icc2rgb)
You should then be able to convert the resulting image to a Numpy array that OpenCV can work with using:
OpenCVim = np.array(result)
and remember to then convert from RGB ordering to BGR with cv2.cvtColor().
Rather than detect and extract the ICC profile with ImageMagick, you could equally use PIL/Pillow like this:
from PIL import Image
im = Image.open('frog.jpg')
# Now look at "im.info"
{'jfif': 257,
'jfif_version': (1, 1),
'dpi': (72, 72),
'jfif_unit': 1,
'jfif_density': (72, 72),
'icc_profile': b'\x00\x00\x020ADBE\x02\x10\x00\x00mntrRGB XYZ \x07\xd0\x00\x08\x00\x0b\x00\x13\x003\x00;acspAPPL\x00\x00\x00\x00none\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf6\xd6\x00\x01\x00\x00\x00\x00\xd3-ADBE\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ncprt\x00\x00\x00\xfc\x00\x00\x002desc\x00\x00\x010\x00\x00\x00kwtpt\x00\x00\x01\x9c\x00\x00\x00\x14bkpt\x00\x00\x01\xb0\x00\x00\x00\x14rTRC\x00\x00\x01\xc4\x00\x00\x00\x0egTRC\x00\x00\x01\xd4\x00\x00\x00\x0ebTRC\x00\x00\x01\xe4\x00\x00\x00\x0erXYZ\x00\x00\x01\xf4\x00\x00\x00\x14gXYZ\x00\x00\x02\x08\x00\x00\x00\x14bXYZ\x00\x00\x02\x1c\x00\x00\x00\x14text\x00\x00\x00\x00Copyright 2000 Adobe Systems Incorporated\x00\x00\x00desc\x00\x00\x00\x00\x00\x00\x00\x11Adobe RGB (1998)\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00XYZ \x00\x00\x00\x00\x00\x00\xf3Q\x00\x01\x00\x00\x00\x01\x16\xccXYZ \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00curv\x00\x00\x00\x00\x00\x00\x00\x01\x023\x00\x00curv\x00\x00\x00\x00\x00\x00\x00\x01\x023\x00\x00curv\x00\x00\x00\x00\x00\x00\x00\x01\x023\x00\x00XYZ \x00\x00\x00\x00\x00\x00\x9c\x18\x00\x00O\xa5\x00\x00\x04\xfcXYZ \x00\x00\x00\x00\x00\x004\x8d\x00\x00\xa0,\x00\x00\x0f\x95XYZ \x00\x00\x00\x00\x00\x00&1\x00\x00\x10/\x00\x00\xbe\x9c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'}
Here's the frog.jpg image:
Keywords: Python, ImageMagick, image, image processing, profile, ICC profile, extract, insert, apply, transform, PIL, Pillow, OpenCV, CMS, pyCMS.
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
I'm using tesseract v 3.02
I have the following image
Download Image (right click -- save link as)
I would like to get the text from it. I'm using tesseract for the purpose.
When writing this command:
tesseract cropped.png tess -psm 7
The result I get is "suackea I 30 10193020 NL 3 e 1 64 :23 23% 34% 120". While the end is ok, the beginning is incorrect. The expected result is:
"Strackea III €0.10/€0.20 NL 6 6 1 €4 €23 23% 34% 120"
I have tried to do some transformation using imageMagick before tesseract to get an image with text written in black on a white background:
convert cropped.png -fuzz 28000 -fill black -opaque white cropped.png
convert cropped.png -fuzz 25000 -fill white -opaque rgb(118,118,118) cropped.png
The resulting image is
Download Image (right click -- save link as)
tesseract cropped.png tess -psm 7
but the result is the same.
What transformation or other command line tool would you use to recognize the text correctly ?)
The font the text is written in is Microsof Sans Serif
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