On Jun 5, 2008, at 7:36 AM, Denis Chabot wrote:
Hi,
a bit frivolous, I know, but I thought of adding a small picture of
each species of fish onto the upper right corner of plots dealing
with metabolic rate of several species of fish.
The only information I could find about doing this involved a
package named pixmap. But from what I understand, I must first make
the picture of each fish (diverse original formats, gif, jpeg, pdf)
into a pnm format.
How do I manage this on Mac OS X? I had never come across this
format before.
IMHO the simplest solution is to save your image(s) into uncompressed
TIFFs (e.g. open the image in Preview and Save As.. , Format: TIFF ,
Compression: None). The you can use this simple function to read TIFFs
into pixmaps:
read.tiff = function(con, ...) {
if (is.character(con)) {
con = file(con, "rb")
on.exit(close(con))
}
sig = readBin(con, 1L, 1, 2)
if (sig != 0x4949 && sig != 0x4d4d) stop("Invalid signature")
end = if (sig == 0x4949) "little" else "big"
if (readBin(con, 1L, 1, 2, endian=end) != 42) stop("Invalid
signature")
o = readBin(con, 1L, 1, 4, endian=end)
data = readBin(con, 1L, o - 8, 1, signed=FALSE, endian=end)
ifds = readBin(con, 1L, 1, 2, endian=end)
info = list()
for (i in 1:ifds) {
tag = readBin(con, 1L, 6, 2, endian=end)
if (tag[1] == 257) info$height = tag[5]
if (tag[1] == 256) info$width = tag[5]
if (tag[1] == 259 && tag[5] != 1) stop("compressed TIFFs are not
supported")
}
if (is.null(info$width)||is.null(info$height)) stop("missing width/
height tags")
res = array(data/255, dim=c(3, info$width, info$height))
z = pixmapRGB(0, ncol = dim(res)[2], nrow = dim(res)[3], ...)
[EMAIL PROTECTED] = t(res[1, , ])
[EMAIL PROTECTED] = t(res[2, , ])
[EMAIL PROTECTED] = t(res[3, , ])
z
}
Cheers,
Simon
I have seen another way using grImport to import postscript vector
graphics. Does anyone here know if this will also work if I
transform my original pictures and drawings into postscript format
(which obvisouly won't be vector based)?
Thanks,
Denis Chabot
_______________________________________________
R-SIG-Mac mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-mac
_______________________________________________
R-SIG-Mac mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-mac