added save-svg-image

This commit is contained in:
Robby Findler 2011-08-07 19:34:48 -05:00
parent 3e8ad26b1f
commit d1e3765af7
4 changed files with 43 additions and 1 deletions

View File

@ -132,6 +132,7 @@ and they all have good sample contracts. (It is amazing what we can do with kids
pen? pen?
step-count? step-count?
save-image save-image
save-svg-image
freeze freeze
bitmap/url) bitmap/url)

View File

@ -76,6 +76,21 @@
(send bdc set-bitmap #f) (send bdc set-bitmap #f)
(send bm save-file filename 'png))) (send bm save-file filename 'png)))
(define/chk (save-svg-image image
filename
[width (if (image? image) (image-width image) 0)]
[height (if (image? image) (image-height image) 0)])
(call-with-output-file filename
(λ (port)
(define sdc (new svg-dc% [width width] [height height] [output port]))
(send sdc start-doc "")
(send sdc start-page)
(send sdc set-smoothing 'aligned)
(render-image image sdc 0 0)
(send sdc end-page)
(send sdc end-doc))
#:exists 'truncate))
(define (get-right img) (bb-right (send img get-bb))) (define (get-right img) (bb-right (send img get-bb)))
(define (get-bottom img) (bb-bottom (send img get-bb))) (define (get-bottom img) (bb-bottom (send img get-bb)))
(define (get-baseline img) (bb-baseline (send img get-bb))) (define (get-baseline img) (bb-baseline (send img get-bb)))
@ -1423,6 +1438,7 @@
save-image save-image
save-svg-image
bring-between bring-between

View File

@ -2031,6 +2031,9 @@
(test/exn (save-image "tri.png" (triangle 50 "solid" "purple")) (test/exn (save-image "tri.png" (triangle 50 "solid" "purple"))
=> =>
#rx"^save-image:") #rx"^save-image:")
(test/exn (save-svg-image "tri.png" (triangle 50 "solid" "purple"))
=>
#rx"^save-svg-image:")
(test/exn (pen 1 2 3 4 5) (test/exn (pen 1 2 3 4 5)
=> =>

View File

@ -1652,12 +1652,19 @@ are not lost if the image is later clipped to its bounding box.
In order to use an image as an input to another program (e.g., Photoshop or In order to use an image as an input to another program (e.g., Photoshop or
a web browser), it is necessary to represent it in a format that these programs a web browser), it is necessary to represent it in a format that these programs
can understand. The @racket[save-image] function provides this functionality, can understand.
The @racket[save-image] function provides this functionality,
writing an image to disk using the @tt{PNG} format. Since this writing an image to disk using the @tt{PNG} format. Since this
format represents an image using a set of pixel values, an image written to disk format represents an image using a set of pixel values, an image written to disk
generally contains less information than the image that was written, and cannot be scaled generally contains less information than the image that was written, and cannot be scaled
or manipulated as cleanly (by any image program). or manipulated as cleanly (by any image program).
The @racket[save-svg-image] function writes an @tt{SVG} file format
representation of the file to the disk that, unlike @racket[save-image] produces
an image that can still be scaled arbitrarily look as good as scaling the
image directly via @racket[scale].
@defproc[(save-image [image image?] @defproc[(save-image [image image?]
[filename path-string?] [filename path-string?]
[width [width
@ -1675,5 +1682,20 @@ or manipulated as cleanly (by any image program).
} }
@defproc[(save-svg-image [image image?]
[filename path-string?]
[width
(and/c real? (not/c negative?))
(image-width image)]
[height
(and/c real? (not/c negative?))
(image-height image)])
void?]{
Writes an image to the path specified by @racket[filename], using the
@tt{SVG} format.
The last two arguments are optional. If present, they determine the width
and height of the save image file. If absent, the width and height of the image is used.
}
@(close-eval img-eval) @(close-eval img-eval)