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

image_composite "reflects" image position when offset moves composite_image out of area of image #381

Open
chroetz opened this issue Aug 27, 2023 · 2 comments

Comments

@chroetz
Copy link

chroetz commented Aug 27, 2023

library(magick)
## Linking to ImageMagick 6.9.12.93
## Enabled features: cairo, freetype, fftw, ghostscript, heic, lcms, pango, raw, rsvg, webp
## Disabled features: fontconfig, x11
image_blank(100, 100, color="pink") |> 
  image_composite(image_blank(20, 50, "yellow"), gravity="center") |> 
  image_composite(image_blank(20, 40, "green"), gravity="center", offset = "+52+0") |> 
  image_composite(image_blank(20, 30, "red"), gravity="center", offset = "-35+0") |> 
  image_composite(image_blank(20, 20, "orange"), gravity="center", offset = "-40+0") |> 
  image_composite(image_blank(20, 10, "blue"), gravity="center", offset = "-50+0")

rect

The blue rectangle should be moved further to the left so that part of it is outside the background image. Instead, the "negative x position" is turned into a positive one. This does not happen on the right border (green rectangle).

Maybe this is connected to #274 ?

sessioninfo::session_info() |>  
    details::details(summary = 'current session info')
current session info
Session info ─────────────────────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.2.3 (2023-03-15 ucrt)
 os       Windows 10 x64 (build 19044)
 system   x86_64, mingw32
 ui       RStudio
 language (EN)
 collate  English_Germany.utf8
 ctype    English_Germany.utf8
 tz       Europe/Berlin
 date     2023-08-27
 rstudio  2023.06.1+524 Mountain Hydrangea (desktop)
 pandoc   NAPackages ─────────────────────────────────────────────────────────────────────────────────────
 package     * version date (UTC) lib source
 cli           3.6.0   2023-01-09 [1] CRAN (R 4.2.2)
 clipr         0.8.0   2022-02-22 [1] CRAN (R 4.2.0)
 desc          1.4.2   2022-09-08 [1] CRAN (R 4.2.2)
 details       0.3.0   2022-03-27 [1] CRAN (R 4.2.3)
 digest        0.6.31  2022-12-11 [1] CRAN (R 4.2.2)
 fastmap       1.1.1   2023-02-24 [1] CRAN (R 4.2.2)
 htmltools     0.5.4   2022-12-07 [1] CRAN (R 4.2.2)
 httr          1.4.5   2023-02-24 [1] CRAN (R 4.2.2)
 knitr         1.42    2023-01-25 [1] CRAN (R 4.2.2)
 magick      * 2.7.5   2023-08-07 [1] CRAN (R 4.2.3)
 magrittr      2.0.3   2022-03-30 [1] CRAN (R 4.2.0)
 png           0.1-8   2022-11-29 [1] CRAN (R 4.2.2)
 R6            2.5.1   2021-08-19 [1] CRAN (R 4.2.0)
 Rcpp          1.0.10  2023-01-22 [1] CRAN (R 4.2.2)
 rlang         1.1.0   2023-03-14 [1] CRAN (R 4.2.2)
 rprojroot     2.0.3   2022-04-02 [1] CRAN (R 4.2.0)
 rstudioapi    0.14    2022-08-22 [1] CRAN (R 4.2.2)
 sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.2.0)
 withr         2.5.0   2022-03-03 [1] CRAN (R 4.2.0)
 xfun          0.39    2023-04-20 [1] CRAN (R 4.2.3)
 xml2          1.3.5   2023-07-06 [1] CRAN (R 4.2.3)

 [1] C:/Users/cschoetz/AppData/Local/R/win-library/4.2
 [2] C:/Program Files/R/R-4.2.3/library

────────────────────────────────────────────────────────────────────────────────────────────────

@jeroen
Copy link
Member

jeroen commented Aug 27, 2023

I see the same on MacOS. It looks not like the negative x is turned into a positive one, but the value wraps around when outside the image?

If I do image_composite(image_blank(20, 10, "blue"), gravity="center", offset = "-40+0") then the blue square is all the way at the left, but further increasing the negative offset makes it bounce back again...

@chroetz
Copy link
Author

chroetz commented Aug 28, 2023

Right! I think we mean the same thing. Assume the left of the background image is $x_{\mathsf{background}}=0$ and the left of the blue rectangle at its intended location is $x_{\mathsf{blue,intent}} = x_{\mathsf{blue,start}} + x_{\mathsf{blue,offset}}$, where $x_{\mathsf{blue,start}}$ is essentially determined by gravity and $x_{\mathsf{blue,offset}}$ is the offset given in the offset parameter. But it seems to be placed at $x_{\mathsf{blue,is}} = |x_{\mathsf{blue,start}} + x_{\mathsf{blue,offset}}|$.

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

2 participants