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 support? #1

Open
ghost opened this issue Jul 18, 2018 · 3 comments
Open

Image support? #1

ghost opened this issue Jul 18, 2018 · 3 comments

Comments

@ghost
Copy link

ghost commented Jul 18, 2018

In the racket-mode REPL I'm able to see the images produced by my code. The following is my output when evaluating the same code in an org-mode buffer. Is this a limitation of org-mode itself?

#+begin_src racket :lang htdp/bsl
(require 2htdp/image)

(rectangle 10 20 "solid" "red")
(rectangle 20 10 "solid" "blue")
(define I1 (rectangle 10 20 "solid" "red"))
(define I2 (rectangle 20 10 "solid" "blue"))
(if (< (image-width I1)
       (image-width I2))
       "tall"
       "wide")
#+end_src

#+RESULTS:
: #<image>
: #<image>
: "tall"
@ghost
Copy link
Author

ghost commented Jul 18, 2018

I've tried (add-hook 'org-babel-after-execute-hook 'org-redisplay-inline-images) receiving the same placeholder result.

@DEADB17
Copy link
Owner

DEADB17 commented Jul 19, 2018

I didn't know racket-mode supported inline images. That's very cool.
It looks like this is the implementation https://github.com/greghendershott/racket-mode/blob/e04635807605c3f7488eb20cd4ebe475529460f8/racket-repl.el#L470-L527
I'm not planning to work on it for now, but if you want to take a stab at it feel free to send a patch. 😉

@xuchunyang
Copy link

Here is a way to produce one inline image:

#+begin_src racket :results raw
#lang racket

(require file/convertible)              ; convert
(require 2htdp/planetcute)              ; character-cat-girl

(define (save-image image filename)
  (with-output-to-file (string->path filename) #:exists 'truncate
    (lambda () (display (convert image 'png-bytes))))
  (display (format "[[file:~a]]" filename)))

(save-image character-cat-girl "out.png")
#+end_src

#+RESULTS:
[[file:out.png]]

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