A bug in the export snapshot command

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

RCozens
Posts: 138
Joined: Thu Aug 05, 2021 6:42 am
Location: Manchester, CA USA

A bug in the export snapshot command

Post by RCozens » Sun Sep 26, 2021 7:38 am

Hi All,

I believe I have found a bug in the export snapshot command, and I need the requisite number of you to agree I should submit a bug report...
or one of you to show me my error.

I created a couple of images that demonstrate the issue, but I have not figured out how to imbed them in this post using html; so let me describe the issue.

Here is the handler in question:

Code: Select all

on createASnapshot theImageType  -- 25 Sep 21:RCC
   put the rectangle of image "New Image Frame" into snapshotRectangle
   set the rectangle of templateImage to snapshotRectangle
   set the showBorder of templateImage to false
   set the threeD of templateImage to false
   create image
   put the id of image (the number of images) into imageIdNumber
   switch theImageType
      case "GIF"
         export snapshot from rectangle snapshotRectangle of this card to image id imageIdNumber as GIF
         break
      case "PNG"
         export snapshot from rectangle snapshotRectangle of this card to image id imageIdNumber as PNG
         break 
      case "PMB"
         export snapshot from rectangle snapshotRectangle of this card to image id imageIdNumber as paint
         break
      case "JPEG"
         if maskImage then
            answer warning "JPEG images do not support masking." with "Turn off masking" or "Cancel"
            if it is "Cancel" then return it
            put false into maskImage
         end if
         export snapshot from rectangle snapshotRectangle of this card to image id imageIdNumber as JPEG
         break
   end switch
   return empty
end createASnapshot
When I run this handler, cases "PNG", "PMB", and "JPEG" export the correct representation of the pixels in snapshotRectangle displayed on the screen; but case "GIF" exports an incorrect image. In one example the snapshot GIF image was split, with the bottom half at the top of the resulting image, the top half on the bottom, and blank space in the middle.

Since the screen rectangle is the same for all four snapshots and the only essential difference in the command is "GIF", "PNG", "PMB", or "JPEG", I find it hard to imagine this is not a bug in the export snapshot command itself...
but i am ready to grovel in mortification if someone proves me wrong.

And, by the way, is there some intrinsic restriction in the compiler that makes it impossible to resolve the image type at runtime?

Code: Select all

put ["GIF"/"PNG"/"PMB"/"paint"] into imageType
export snapshot from rectangle snapshotRectangle of this card to image id imageIdNumber as imageType
The Script Editor flags a statement like that as a syntax error.

Cheers!
Rob Cozens dba Serendipity Software Company
Manchester, CA USA

Each new generation gives more attention to the man-made world...
and less attention to the world that made man.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: A bug in the export snapshot command

Post by richmond62 » Sun Sep 26, 2021 9:25 am

OK: I got out my bucket and spade (LC 9.6.5 RC-1) and . . .
-
SShot 2021-09-26 at 11.21.29.jpg
-
This uses an extremely pedestrian code, but I thought I would just check
to see if that would muck up a GIF export:
-

Code: Select all

on mouseUp
   export snapshot from img "Kali" to file "Kali.gif" as GIF
   export snapshot from img "Kali" to file "Kali.jpg" as JPEG
   export snapshot from img "Kali" to file "Kali.png" as PNG
end mouseUp
-
and a GIF image was exported with no problems whatsoever.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: A bug in the export snapshot command

Post by richmond62 » Sun Sep 26, 2021 9:32 am

This:
-

Code: Select all

on mouseUp
   export snapshot from rectangle "100,52,501,349" of window 473 to file "Kali1.gif" as GIF
   export snapshot from rectangle "100,52,501,349" of window 473 to file "Kali1.jpg" as JPEG
   export snapshot from rectangle "100,52,501,349" of window 473 to file "Kali1.png" as PNG
end mouseUp
-
Worked equally well.
I created a couple of images that demonstrate the issue, but I have not figured out how to imbed them in this post using html; so let me describe the issue.
How about attaching them to a post exactly like I did with the image in my previous message?

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: A bug in the export snapshot command

Post by Klaus » Sun Sep 26, 2021 10:16 am

Hi Rob,

Code: Select all

put ["GIF"/"PNG"/"PMB"/"paint"] into imageType
export snapshot from rectangle snapshotRectangle of this card to image id imageIdNumber as imageType
no wonder the engine complains!
1. this is not a valid string nor anything else
2. export snapshot .... as TYPE -> requires only ONE format description
So I'm not sure what you are exspecting the engine to use as the format here with your -> imageType?

And save some typing by using RECT instead of RECTANGLE. :-)


Best

Klaus

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: A bug in the export snapshot command

Post by richmond62 » Sun Sep 26, 2021 12:10 pm

Klaus, one man's RECTANGLE is another man's SQUARE, and, personally I used RECTANGLE in my example
code for those who might confuse RECT, UM, with something else . . . 8)

Think "bottom feeders" . . .

I sue export snapshot at least twice a week and have never, ever had any problem with it, but
am always extremely careful to define the image type.

RCozens
Posts: 138
Joined: Thu Aug 05, 2021 6:42 am
Location: Manchester, CA USA

Re: A bug in the export snapshot command

Post by RCozens » Sun Sep 26, 2021 6:46 pm

richmond62 wrote:
Sun Sep 26, 2021 9:25 am
This uses an extremely pedestrian code, but I thought I would just check
to see if that would muck up a GIF export:
-

Code: Select all

on mouseUp
   export snapshot from img "Kali" to file "Kali.gif" as GIF
   export snapshot from img "Kali" to file "Kali.jpg" as JPEG
   export snapshot from img "Kali" to file "Kali.png" as PNG
end mouseUp
-
and a GIF image was exported with no problems whatsoever.

Hi Richmond,

From the LiveCode Dictionary:
If taking a snapshot of an object, the rectangle's coordinates are relative to the top left corner of the card containing the object. The object is rendered into an image as if no other objects existed around it, the snapshot is taken without applying the object's blendlevel or ink. You can take a snapshot of an object regardless of its visibility or open status
I don't want image "New Image Frame" to be rendered. I want the visible pixelation of the screen rectangle bounded by "New Image Frame" to be rendered. My code works exactly as I expect it if I export to PNG, PBN, and JPEG formats. Only GIF format fails. And the rectangle I am rendering contains multiple images. In the particular case in point I have my generic Wine Press image along side my generic Id# image and I want to render a Wine Press Id # image that is a composite of the two. I size and position "New Image Frame" so that its rectangle encompasses both original images. In one of my examples I created a single image showing six images: the original two plus each of the four attempts at rendering.
Rob Cozens dba Serendipity Software Company
Manchester, CA USA

Each new generation gives more attention to the man-made world...
and less attention to the world that made man.

RCozens
Posts: 138
Joined: Thu Aug 05, 2021 6:42 am
Location: Manchester, CA USA

Re: A bug in the export snapshot command

Post by RCozens » Sun Sep 26, 2021 7:10 pm

Klaus wrote:
Sun Sep 26, 2021 10:16 am
Hi Rob,

Code: Select all

put ["GIF"/"PNG"/"PMB"/"paint"] into imageType
export snapshot from rectangle snapshotRectangle of this card to image id imageIdNumber as imageType
no wonder the engine complains!
1. this is not a valid string nor anything else
2. export snapshot .... as TYPE -> requires only ONE format description
So I'm not sure what you are exspecting the engine to use as the format here with your -> imageType?

And save some typing by using RECT instead of RECTANGLE. :-)
Morning Klaus,

The first line was my attempt to duplicate LiveCode Dictionary command syntax. By
put ["GIF"/"PNG"/"PMB"/"JPEG"] into imageType
, I mean
put one of the four options stated into imageType
.

I recognize that "location" , "rectangle" and other LiveCode properties can be abbreviated, and sometimes when i am in a hurry I do so; however my personal goal when scripting is to write syntax that emulates written instructions. I want my code to read like a book. That is why I do not follow LiveCode's recommendation to prefix a variable names with a character designating the variable type: when I read such code my mind sees it as stuttering. And I figure the extra time spent typing in the Script Editor now will reduce the time I have to spend trying to remember what the script was all about if I need to change it sometime in the future.

Cheers!
Rob Cozens dba Serendipity Software Company
Manchester, CA USA

Each new generation gives more attention to the man-made world...
and less attention to the world that made man.

RCozens
Posts: 138
Joined: Thu Aug 05, 2021 6:42 am
Location: Manchester, CA USA

Re: A bug in the export snapshot command

Post by RCozens » Sun Sep 26, 2021 7:16 pm

richmond62 wrote:
Sun Sep 26, 2021 9:32 am
I created a couple of images that demonstrate the issue, but I have not figured out how to imbed them in this post using html; so let me describe the issue.
How about attaching them to a post exactly like I did with the image in my previous message?
The issue here is my ignorance. I have snapshotTest1.png and snapshotTest2.gif on my Windows desktop, but I don't understand how to attach them to my reply here.
Rob Cozens dba Serendipity Software Company
Manchester, CA USA

Each new generation gives more attention to the man-made world...
and less attention to the world that made man.

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: A bug in the export snapshot command

Post by Klaus » Sun Sep 26, 2021 7:26 pm

Good evening (I'm in germany) Rob,

OK, got it! :-)


Best

Klaus

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: A bug in the export snapshot command

Post by richmond62 » Sun Sep 26, 2021 7:50 pm

I don't understand how to attach them to my reply here.
-
SShot 2021-09-26 at 21.50.24.png

RCozens
Posts: 138
Joined: Thu Aug 05, 2021 6:42 am
Location: Manchester, CA USA

Re: A bug in the export snapshot command

Post by RCozens » Sun Sep 26, 2021 8:34 pm

Thank you for reducing my ignorance Richmond.

The PNG image shows the two original images on the left and the four images created from snapshots on the right. The top right image is the GIF image.

The GIF image shows the snapshot of the same rectangle as the PNG rendering. If you look closely at the left side of it you will see a loose representation of the bottom of the two original images followed by blank space followed by the top half of the original images.

Cheers!
Attachments
SnapshotTest2.gif
SnapshotTest2.gif (2.15 KiB) Viewed 4755 times
SnapshotTest1.png
SnapshotTest1.png (4 KiB) Viewed 4755 times
Rob Cozens dba Serendipity Software Company
Manchester, CA USA

Each new generation gives more attention to the man-made world...
and less attention to the world that made man.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7228
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: A bug in the export snapshot command

Post by jacque » Mon Sep 27, 2021 7:10 am

I'd call it a bug.

BTW, the "of this card" isn't necessary. Object references are only needed if you want the whole object snapshotted. (And cards aren't objects, really.)

Code: Select all

export snapshot from rectangle snapshotRectangle to image id imageIdNumber
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: A bug in the export snapshot command

Post by richmond62 » Mon Sep 27, 2021 11:46 am

cards aren't objects
Ooh, let's go off on a tangent . . . 8)

So, what is an object and what isn't?

RCozens
Posts: 138
Joined: Thu Aug 05, 2021 6:42 am
Location: Manchester, CA USA

Re: A bug in the export snapshot command

Post by RCozens » Mon Sep 27, 2021 5:10 pm

Here are a two more images that might help LiveCode unravel what's happening here.

They are taken from the same screen rectangle as the first two, except that image "New Image Frame" has a visible border.

SnapshotTest3.jpg demonstrates that my export snapshot handler works for JPEGs as well a PNGs.

SnapshotTest4.gif shows how exporting the snapshot as GIF renders the four-pixel border of the images at the top and bottom of the screen. Note that there seems to be two or more blank lines between each of the four single-pixel lines in the border displayed at the top of the image and one blank line between each of the four single-pixel lines displayed at the bottom of the image. (Of course, the image appears to be split with the bottom at the top and the top at the bottom; so the single-space lines at the bottom may have been rendered from the top border and vice versa.)

Cheers!
Attachments
SnapshotTest3.jpg
SnapshotTest3.jpg (14.99 KiB) Viewed 4580 times
SnapshotTest4.gif
SnapshotTest4.gif (2.55 KiB) Viewed 4580 times
Rob Cozens dba Serendipity Software Company
Manchester, CA USA

Each new generation gives more attention to the man-made world...
and less attention to the world that made man.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7228
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: A bug in the export snapshot command

Post by jacque » Mon Sep 27, 2021 5:22 pm

richmond62 wrote:
Mon Sep 27, 2021 11:46 am
cards aren't objects
Ooh, let's go off on a tangent . . . 8)

So, what is an object and what isn't?
As I understand it, anything that goes on a card; basically the stuff in the tool palette. The card itself isn't an object and I don't think a stack is either but it gets hazy for me at that point. Mark Waddingham mentioned once that cards aren't objects, though they do have properties, so I suspect the distinction is largely internal to the engine.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply

Return to “Talking LiveCode”