beetlebug▾
/

image read

A command of a photo: reads an image file into the photo.

IMAGENAME read FILENAME ?-format FORMAT? ?-to X Y? ?-shrink?

Description

Decodes the file and puts its pixels at X Y, 0 0 by default. A photo with no -width or -height grows to hold them. The file opens through the file commands of the script, as for -file. -format and -shrink are accepted, and the decoder finds the format from the data.

Returns

An empty string.

Examples

% set png iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8DwHwAFBQIAX8jx0gAAAABJRU5ErkJggg==
> set f [open dot.png wb]
> puts -nonewline $f [binary decode base64 $png]
> close $f
> image create photo r
> r read dot.png -to 2 1
> file delete dot.png
> list [image width r] [image height r] [r get 2 1]
3 2 {255 0 0}

Errors

% image create photo r2; r2 read /nonexistent/a.png
couldn't open "/nonexistent/a.png": no such file or directory
-errorcode POSIX ENOENT {no such file or directory}

% image create photo r3; r3 read a.png -from 0 0 1 1
bad option "-from": must be -format, -from, -shrink, or -to
-errorcode NONE

% image create photo r4; r4 read
wrong # args: should be "r4 read fileName ?-option value ...?"
-errorcode NONE

Differences from Tcl

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztk 1.0.0-beta.1

See also