Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cropped raster image #64

Closed
steveharoz opened this issue Mar 28, 2016 · 3 comments
Closed

cropped raster image #64

steveharoz opened this issue Mar 28, 2016 · 3 comments

Comments

@steveharoz
Copy link

When including a rastergrob in a plot, it displays without issue in Rstudio. However, much of the image is cropped when outputting the plot with svglite.

Reproducible example:

library(ggplot2)
library(svglite)
library(grid)
library(RCurl)
library(png)

# get raster image
img <- readPNG(getURLContent("https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/280px-PNG_transparency_demonstration_1.png"))
imgGrob <- rasterGrob(img, interpolate=TRUE)

# make plot and add raster image
ggplot(data.frame(x=1:10, y=1:10)) +
  geom_point(aes(x=x, y=y)) +
  theme_void() +
  annotation_custom(imgGrob, xmin=5, xmax=8, ymin=2, ymax=5)

# save as svg file
#ggsave('test.svg', width=10, height=8) # equivalent ggsave call
svglite::svglite('test.svg', width=10, height=8)
last_plot()
dev.off()

Output in Rstudio:
image

Output from svglite:
image

@hadley
Copy link
Member

hadley commented Aug 15, 2016

Simpler reprex:

url1 <- "https://upload.wikimedia.org/wikipedia/commons/6/68/Solid_black.png"
url2 <- "https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/280px-PNG_transparency_demonstration_1.png"
img <- png::readPNG(curl::curl_fetch_memory(url2)$content)

htmlSVG({
  plot.new()
  rasterImage(img, 0.25, 0.25, 0.75, 0.75)
  rect(0.25, 0.25, 0.75, 0.75, border = "red", lwd = 2)
})

Interestingly, the problem doesn't seem to occur with the solid black png

@hadley
Copy link
Member

hadley commented Aug 15, 2016

@davidgohel given that this only happens with some images, is it possible it's a bug in gdtools?

lionel- added a commit to lionel-/gdtools that referenced this issue Oct 21, 2016
Fixes r-lib/svglite#64
Fixes bug in transparency handling
@lionel-
Copy link
Member

lionel- commented Oct 21, 2016

Fixed in davidgohel/gdtools#32

lionel- added a commit to lionel-/svglite that referenced this issue Oct 24, 2016
@hadley hadley closed this as completed in 2f8b45d Oct 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants