Tk Source Code

View Ticket
Login
Ticket UUID: 1576528
Title: image read file with -from co-ords
Type: Bug Version: obsolete: 8.5a4
Submitter: alastair_davies Created on: 2006-10-13 12:35:21
Subsystem: 42. Photo Image|GIF Assigned To: fvogel
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2024-06-11 03:37:26
Resolution: Fixed Closed By: fvogel
    Closed on: 2024-06-11 03:37:26
Description:
The /image/ read /file/ -from x1 y1 x2 y2 command does
not work correctly.  The following script uses the
ActiveTcl example gif of the earth from space.  The
rectangular region (152,62) to (185,97) encloses
Madagascar.  The displayed region is from the top-right
hand corner.

package require Tk
set fname C:/Tcl8.4/demos/Tk8.4/images/earth.gif
canvas .c
pack .c
set img [image create photo]
$img read $fname -from 152 62 185 97
.c create image 0 0 -anchor nw -image $img
User Comments: fvogel added on 2024-06-11 03:37:26:
Thank you for your feedback. This is now merged.

serhiy.storchaka added on 2024-06-10 08:10:51:

The Tkinter tests are also now passed if change them to use GIF or PNG.

I think everything is working as expected now.


fvogel added on 2024-06-09 18:57:09:

Thanks for the suggestions.

There was indeed a bug regarding the width and the height of the PNG file, I have fixed it in [55a99a75f0] (with tests).

I have also added a number of further tests, reading GIF or PNG files with both -fom and -to, or with all options (-from, -to, and -shrink) at the same time. Also a test exercising the corner case you described. All of them pass.

Regarding 'copy' there are already quie a number of existing tests in the test suite, I didn't identify what could be missing.

Let me know if something is still missing.


serhiy.storchaka added on 2024-06-09 16:02:02:

I think it is worth to add more tests:

  • Test also the image's width and height after reading.
  • Test options -from and -to together. And maybe in combination with -shrink option when read in a non-empty image.
  • There are some corner cases, for example when you read a large region from a small file -- how does it affect the image size?
  • Since the code is format-specific, all tests should be repeated for all formats (PPM, GIF, PNG).
  • Perhaps new tests for copy should be added too.

serhiy.storchaka added on 2024-06-09 15:11:36:

It was fast!

But it seems that the width and the height of the PNG file are set to the width and the height of the original file instead of the selected rectangle, as for the PPM file. I have not tested the GIF file.


fvogel added on 2024-06-09 12:18:13:

PNG case now fixed as well, with testcases added. See branch bug-1576528fff.

@Serhiy, in your opinion, is there anything else remaining to be fixed in the frame of this ticket?


fvogel added on 2024-06-08 20:50:54:

I have now fixed the GIF case, see branch bug-1576528fff.


fvogel added on 2024-06-08 19:45:29:
Let me have a look.

serhiy.storchaka added on 2024-06-08 12:02:31:

This old bug has not been fixed yet.

Reading an image from a file was recently implemented in Tkinter (https://github.com/python/cpython/issues/118271), but the tests are forced to use PPM files, because the -from option does not work correctly for GIF and PNG files.

The -from option works correctly with the copy subcommand, so this may be some simple bug in the read subcommand.


alastair_davies added on 2006-10-13 19:45:05:
Logged In: YES 
user_id=988604

Just for comparison, here is the equivalent /image/ copy
/image/ -from x1 y1 x2 y2 code, which does work correctly.

package require Tk
set fname C:/Tcl8.4/demos/Tk8.4/images/earth.gif
canvas .c
pack .c
set img1 [image create photo -file $fname]
set img2 [image create photo]
$img2 copy $img1 -from 152 62 185 97
.c create image 0 0 -anchor nw -image $img2