-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9497e21
commit 42267c9
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
Extension { #name : #ZnEasy } | ||
|
||
{ #category : #'*GToolkit-Extensions' } | ||
ZnEasy class >> gtGetImageOfType: mimeType fromUrl: urlObject [ | ||
| client readStream pictureBytes | | ||
(client := self client) | ||
url: urlObject; | ||
accept: mimeType; | ||
enforceHttpSuccess: true; | ||
enforceAcceptContentType: true; | ||
get. | ||
|
||
readStream := client entity readStream. | ||
pictureBytes := readStream upToEnd. | ||
readStream close. | ||
|
||
"We create a SkiaImage and use it to get the form." | ||
^ (SkiaImage | ||
fromBuffer: pictureBytes | ||
start: 0 | ||
end: pictureBytes size - 1) asForm | ||
] | ||
|
||
{ #category : #'*GToolkit-Extensions' } | ||
ZnEasy class >> gtGetPng: urlObject [ | ||
"Use SkiaImage to convert bytes to a Form to avoid possible parsing errors in PNGs images." | ||
|
||
"self getPng: 'http://pharo.org/files/pharo.png'." | ||
"(self getPng: 'http://chart.googleapis.com/chart?cht=tx&chl=', | ||
'a^2+b^2=c^2' urlEncoded) asMorph openInHand." | ||
|
||
^ self | ||
gtGetImageOfType: ZnMimeType imagePng | ||
fromUrl: urlObject | ||
] |