jthomasmock / gtExtras

A Collection of Helper Functions for the gt Package.
https://jthomasmock.github.io/gtExtras/
Other
195 stars 27 forks source link

gt_img_circle with color back ground #98

Closed IvoVillanueva closed 1 year ago

IvoVillanueva commented 1 year ago

Prework

gt_img_circle does not allow to fill the background in png img

Proposal

this one I did this with the library cropcircles and uploads png image in github circle_crop( "https://cdn.statmuse.com/img/nba/players/washington-wizards-jabari-parker-min--0vxs4xoe.png", to = "was-colour-bg.png", border_size = 4, border_colour = "#002b5c" )

Captura de pantalla 2023-08-20 a las 18 20 57

Would it be possible to include a similar function in gt_img_circle?

thank you very much

jthomasmock commented 1 year ago

Howdy!

I don't see a way that circle_crop() fills the background? https://github.com/doehm/cropcircles/blob/f96b80f69fef89ebf6430864e72b4270b7db31a2/R/crop.R#L46C6-L71

It appears to be taking an arbitrary image, cropping to a circle and adding a border. I don't see any code that modifies the image background color itself. Unless I'm missing something, gt_img_circle() accomplishes the same task of taking a square image, cropping to a circle, and adding a colored border.

In general, changing the content of the image itself is better suited to the magick package and it's interface to Image Magick.

Modifying the background of images is non-trivial and out of scope for the gt_img_circle() function, but see this blogpost for an example of how to generate local images with a modified background that then could be loaded into a gt table.

https://themockup.blog/posts/2021-01-28-removing-image-backgrounds-with-magick/index.html

Closing for now, but let me know if I missed something.