Support file/convertible 'png-bytes+bounds ?
greghendershott opened this issue · comments
I noticed that objects produced by plot
don't seem to support the 'png-bytes+bounds
format for file/convert
's convert
:
#lang racket/base
(require plot)
(define p (plot (function (λ (x) (sin (* 4 x))) -1 1)
#:x-min -1.5 #:x-max 1.5y-min -1.5 #:y-max 1.5))
(require file/convertible)
(and (convert p 'png-bytes) #t) ;#t Hooray!
(and (convert p 'png-bytes+bounds) #t) ;#f Boo!
Although I'm not familiar with plot
, I think I managed to follow the breadcrumbs from plot
to image-snip%
, and to this code in this snip-lib
repo:
(define png-convertible<%>
(interface* ()
([prop:convertible
(lambda (img format default)
(cond
[(or (eq? format 'png-bytes)
(and (eq? format 'png@2x-bytes)
(= 2 (send (send img get-bitmap) get-backing-scale))))
(let ([s (open-output-bytes)])
(send (send img get-bitmap) save-file s 'png
#:unscaled? (eq? format 'png@2x-bytes))
(get-output-bytes s))]
[else default]))])))
I considered attempting a PR, but, I have very low hands-on mileage with Racket GUI things. For example, I'm not confident how to get the bounds. Maybe using snip%
get-extent
... but maybe not that simple? So for now I wanted to just open this issue in case someone else might find this easy and/or interesting to do?
p.s. For me personally, this isn't urgent. It's barely even nice-to-have: It would enable the Racket Mode REPL pretty-print short lists of small plots on a single line. Not a huge deal IMHO. But maybe more important to other people doing other things.