How to export revBrowserSnapshot to file?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

alex298
Posts: 101
Joined: Mon May 01, 2006 1:17 pm

How to export revBrowserSnapshot to file?

Post by alex298 » Wed Aug 25, 2010 9:36 am

Hello,

I read the sample Browser how to snapshot a revBrowser.
revBrowserSnapshot tBrowserId, "tImgData"

local tOldRect
put the rect of img "thumbnail" into tOldRect

set the rect of img "thumbnail" to the rect of img "browserImage"
set the imageData of img "thumbnail" to tImgData
set the resizeQuality of img "thumbnail" to "best"
set the rect of img "thumbNail" to tOldRect
In the above example, the snapshot image of revBrowser was set to the img "thumbnail". How can I export the snapshot of revBrowser directly to a file?

Thanks and best regards
Alex
Nice to meet all of you.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3458
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: How to export revBrowserSnapshot to file?

Post by bn » Wed Aug 25, 2010 6:01 pm

Hi Alex,

I dont get the revBrowserSnapshot to work. I am on a Mac OSX 10.6.4 Rev 4.0.

What works is to take a snapshot with the export snapshot command

Code: Select all

on mouseUp
   -- turn the local coordinate into global coordinates
   put globalLoc (the topleft of image "browserImage") into tTopLeft
   put globalLoc (the bottomright of image "browserImage") into tBotRight
   put (tTopLeft & "," & tBotRight) into tRectSnap
   put specialfolderpath("desktop") & "/" & "snapExport.png"  into tPathAndName
   export snapshot from rect tRectSnap to file tPathAndName as png
end mouseUp
this is the original size picture.
If you want to export a thumbnail directly I am afraid that does not work. But you can resize the original snapshot via the thumbnail and than export.

Code: Select all

on mouseUp
   lock screen
   put the rect of image "thumbnail" into tThumbRect
   put globalLoc (the topleft of image "browserImage") into tTopLeft
   put globalLoc (the bottomright of image "browserImage") into tBotRight
   put (tTopLeft & "," & tBotRight) into tRectSnap
   export snapshot from rect tRectSnap to tImgData as png
   set the text of img "thumbnail" to tImgData
   set the rect of image "Thumbnail" to tThumbRect
   put specialfolderpath("desktop") & "/" & "ThumbExport.png"  into tPathAndName
   export image "thumbnail" to file tPathAndName as png
end mouseUp
this should work if you put it into two buttons that you add to the Browser Sample.
regards
Bernd

alex298
Posts: 101
Joined: Mon May 01, 2006 1:17 pm

Re: How to export revBrowserSnapshot to file?

Post by alex298 » Thu Aug 26, 2010 4:35 am

Hi Bernd,

Thanks! I can export the browser snap shot to file now. However I face another problem:

The width and height of the web pages are quite large (about 1200 pixels x 1200 pixels. Actually I only want to snap shot a small region (400 pixels x 350 pixels) of the web pages somewhere near the right bottom.

Therefore I am thinking to scroll the vertical bar and horizontal bar of the browser to the desired position to snap shot the screen. However I noticed that the snap shot is always starts from the left top corner of the browser screen no matter the scrolled positions of the vertical bar and horizontal bar.

I have some questions:

1. Is it possible to snap shot the browser screen at "scrolled position"?

2. If the answer of question 1 is yes. What is the codes to move and control the positions of the scroll bars?

Thanks and best regards
Alex
Nice to meet all of you.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3458
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: How to export revBrowserSnapshot to file?

Post by bn » Fri Aug 27, 2010 12:22 am

Hi Alex,

again, I can not test revBrowserSnapshot since it does not work for me. The workaround I showed you with the export snapshot command uses the screen coordinates = absolute coordinates and will dutifully take a snapshot of the region of interest.
So if you know exactly where your area of interest is you could get the local coordinates and converte them to global coordinates and use that in the scripts I posted.

If you want to go the way of the scrolling you definitely can do that. It is a little tricky but it works.
suppose you have initialised your browser instance and store the id in a global variable gBrowserId then you can put this into a vertical scrollbar right next to the browser

Code: Select all

global gBrowserId

on scrollbarDrag theValue
    revBrowserSet gBrowserId, "vScroll", theValue
end scrollbarDrag

on mouseDown
   lock screen
   put revBrowserGet (gBrowserId, "vScroll") into tOldVScroll
   revBrowserSet gBrowserId, "vScroll", "100000"
   put revBrowserGet (gBrowserId, "vScroll") into tVScroll
   revBrowserSet gBrowserId, "vScroll", tOldVScroll
   set the startValue of me to 0
   set the endValue of me to tVScroll
end mouseDown
this goes into a horizontal scrollbar

Code: Select all

global gBrowserId

on scrollbarDrag theValue
    revBrowserSet gBrowserId, "hScroll", theValue
end scrollbarDrag

on mouseDown
   lock screen
   put revBrowserGet (gBrowserId, "hScroll") into tOldHScroll
   revBrowserSet gBrowserId, "hScroll", "100000"
   put revBrowserGet (gBrowserId, "hScroll") into sHScroll
   revBrowserSet gBrowserId, "hScroll", tOldHScroll
   set the startValue of me to 0
   set the endValue of me to sHScroll
end mouseDown
Now you have srollbars that
a let you see what the scroll (vertical and horizontal) is and you can then set the scroll with revBrowserSet. This works regardless of whether the scrollbars of the browser object are visible or not. Just max scroll increases by 15 v and 15 h if they are visible.
That way you could manually find out at what scroll the area of interest is and set it by script and then do a revBrowserSnapshot from a small browser window.
However I noticed that the snap shot is always starts from the left top corner of the browser screen no matter the scrolled positions of the vertical bar and horizontal bar
I tried this. If I dont create a new browser instance then this does not happen. In your code do you make shure you only initialize the browser once?

If you could give me an example site of what you are trying to do I could cook up a little stack to show what I mean. (like on http://www.xyz.com I always want to have a thumbnail of the weather or somesuch)

regards
Bernd

alex298
Posts: 101
Joined: Mon May 01, 2006 1:17 pm

Re: How to export revBrowserSnapshot to file?

Post by alex298 » Wed Sep 01, 2010 10:58 am

Hi Bernd,

Thanks for your codes. It works!

I have spent the past week to play around with the localLoc. However I have still no any idea how the localLoc works. It seems that the results are very strange and do not follow a fixed pattern.

Finally I decide to use globalLoc to get the location of the area I wish to get. I layout a very long and wide browser on the stack. Since the area I wish to snap shot is near the bottom right of the long and wide web page, I moved the browser up and to the left beyond the top and left side of the stack. This way only the required portion of the web page was displayed on the browser.

Then I use globalLoc (actually trial and error) to get the required snap area. Moreover I have to set the location of the stack before the snap shot. It works!

Best regards
Alex
Nice to meet all of you.

openworld
Posts: 63
Joined: Sat Sep 11, 2010 3:56 am
Location: Virginia, USA
Contact:

Re: a revBrowser problem with LiveCode 4.5

Post by openworld » Sat Oct 23, 2010 1:08 am

Bernd (and all),

I've had a big challenge getting the revBrowser demo stack to work (Mac OS 10.6 & Livecode 4.5).

Although demo stack launches a web browser to www.google.com, its page contents are not visible. And in all of the following cards, the embedded browser in each card is similarly blank.

When I get to the card with the "snapshot" button, though, an interesting development occurs. Although the browser pane in on this card continues to remain blank, the display area for the snapshot isn't emply. Instead, it shows a (very) distorted, italicized-looking image of the Google logo. (I've tried various resizings of the embedded browser pane, but not found any that result in a clear snapshot of the web page).

Do you know what change might make the web page visible in the embedded browser area?

You were kind to offer earlier to email a simple demo stack that includes a (working) browser area embedded. I'd be grateful if you have one that would work with Livecode on the Mac.

Look forward to any insights or help you can give!

Best,

Mark Frazier
markf {at] openworld {dot] com

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3458
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: How to export revBrowserSnapshot to file?

Post by bn » Sat Oct 23, 2010 2:05 pm

Hi Mark,

I did a little stack that takes a snapshot of the browser. Please look at the code, there are some comments.
A word of caution: the RevBrowser is an external. This external does not like, if you send the parameters wrongly. I crashed Livecode a couple of times during set up of this stack. Once I even managed to crash all open programs including the Finder. That was when I did not close the browser instances when quitting Livecode. I was using Livecode 4.5 and MacOSX 10.6.4

The bottomline is: do save your stacks frequently during development, which is a good idea anyways.
This does not mean not to use the RevBrowser, if set up properly and used properly it works quite allright. Though I dont do much with RevBrowser.

I added a field where you can drag/drop text from the browser into. This will be html text and Rev has a limited subset of html that it supports. So not all attributes may show up.
Rev stores the html text in a property that you can access with the htmlText of a field.
put the htmlText of field 1 into field 2
will put the html-source of field 1 into field 2, if field 1 has any.
I added a button to convert the html text to plain text and a button to set the textHeight of the field, which is the height of a line.

if you crash the WWW with my little stack we will all have a couple of days off next week, except the system administrators... :)
I did test it, though not extensively, be careful, see above.
regards
Bernd
Attachments
SnapFromBrowser.livecode.zip
(2.94 KiB) Downloaded 205 times

openworld
Posts: 63
Joined: Sat Sep 11, 2010 3:56 am
Location: Virginia, USA
Contact:

Re: How to export revBrowserSnapshot to file?

Post by openworld » Sat Oct 23, 2010 2:56 pm

Bernd,

Thank you for the revBrowser demo stack!

On launching it (while I had the SmartProperties and revNavigator plugins running), I encountered this error --

>>stack "SmartProperties": execution error at line 110 (Chunk: no target found), char 18

executing at 9:41:53 AM
Type Chunk: no target found
Object SmartProperties
Line if the long id of the selectedObject is the cObjRef of fld "ObjL"
Hint UpdateObjet

I then deactivated the plugins - and saw no error messages when trying the demo stack.

Yet the browser pane (and the snapshot pane) remained blank, no matter what sequence of button clicks I tried.

What will be the best way to trace what is causing the issue?

Best,

Mark

openworld
Posts: 63
Joined: Sat Sep 11, 2010 3:56 am
Location: Virginia, USA
Contact:

Re: How to export revBrowserSnapshot to file?

Post by openworld » Sat Oct 23, 2010 3:37 pm

Bernd,

Another insight - I hope - into the problem ...

When I check the script in the "Initialize Browser" button, there's an issue with this line:

put revBrowserOpen(tWinID,"http://www.openworld.com/openworld-people/") into gBrowserId

Although I don't get an error message when I press the button, it turns out the gBrowserId variable isn't being filled with the desired string.

When I check the above line from the button script into the message box, it returns:

>>Message execution error:
>>Error description: Handler: can't find handler
>>Hint: put

I then tried "put gBrowserId in to msg" -- and gBrowserId returns a value of "1".

Hope this helps in the problem tracing!

Best,

Mark

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3458
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: How to export revBrowserSnapshot to file?

Post by bn » Sat Oct 23, 2010 4:48 pm

Mark,
sorry to hear that. I tried and it worked for me. Though I twice had a blank browser. I guess it is a timing problem. The URL was in maintenance when I tried (openworld) but now it is up.
I just sprinkeld some waits into the script to give it all a little more time.
I then tried "put gBrowserId in to msg" -- and gBrowserId returns a value of "1".
this is a legitimate browser id. The id is incremented by one everytime a new instance is created. You can see this in the stack I attach that has a field where the browser Id is shown when it is created.

Try this stack. If it still fails try to set the URL to "http://www.google.com" since it is a very lightweight site and usually very fast.

I think we can figure this out.

regards
Bernd
Attachments
SnapFromBrowserII.livecode.zip
(3.09 KiB) Downloaded 170 times

openworld
Posts: 63
Joined: Sat Sep 11, 2010 3:56 am
Location: Virginia, USA
Contact:

Re: How to export revBrowserSnapshot to file?

Post by openworld » Sat Oct 23, 2010 5:38 pm

Bernd,

Appreciate your abiding interest and followthrough!

The new stack was helpful in showing status. The browser window seems to initialize (with 1 instance of the browser in the status field) but the browser display pane is still bank. The snapshot pane also doesn't display any image.

I've changed the default URL to google.com as suggested, without any change.

Do you think it may be a plug-in related issue? All of my current plugins -- which I've deactivated -- are here:

revTabRuler
RegExBuilder
revExample
GoRevNet
SmartProperties
revSmartSave
revNavigator

I'm running the latest Mac OSX (10.6.4) on an Intel Macbook with latest Firefox (3.61) browser.

Look forward to any further insights/progress!

Best,

Mark

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3458
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: How to export revBrowserSnapshot to file?

Post by bn » Sat Oct 23, 2010 5:49 pm

Mark,
the plug-ins should not interfere, I hope, but it is better to deaktivate them.

As far as I understand the Revbrowser external uses the underlying system browser, Safari in your case. Does your Safari work with the URL's?

I will do a new stack that does the sequence of initializing and fetching a URL in separate handlers. Lets see what that gives.

The snaphshot of the white browser window should be a white image as soon as you click the button. If you click on the take snapshot button it will first look whether you have a number in your global gBrowserID if yes it will take a snapshot of the area of the placeholder graphic, whatever shows up there.

did you try to click on any of the other URL's in the scrolling list field once you get a browser id?

regards
Bernd

openworld
Posts: 63
Joined: Sat Sep 11, 2010 3:56 am
Location: Virginia, USA
Contact:

Re: How to export revBrowserSnapshot to file?

Post by openworld » Sat Oct 23, 2010 6:29 pm

Bernd,

I've tried a couple of times now after changing the default browser to Safari and the default page to Google.com... still no browser display in the left-hand display pane for revBrowser.

Rather than turning white, that pane remains gray (as does the snapshot pane, even after clicking the "take snapshot" button.)

The browser ID field, however, does return "1" when I click the "initialize browser" button.

Could a new demo stack export the activity messages in a way that could show where the holdup is?

Look forward to next ideas -- I appreciate your kindness!

Best,

Mark

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3458
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: How to export revBrowserSnapshot to file?

Post by bn » Sat Oct 23, 2010 6:31 pm

Mark,
could you try this version? Click the sequence of the three buttons, waiting between each click just a couple of seconds.
Clicking the first button initializes the browser and should show a blank white over the area of the placeholder graphic. If that is so the browser is initialized allright.
Then click on the "go openworld" button. wait. for me in under 2 seconds there is the website displayed.
if the site is displayed you might want to try button "find Mark Frazier" it tries to find the name on the site.

Once you get a website you can try a snapshot.

tell me what happens

regards

Bernd
Attachments
SnapFromBrowser-3.livecode.zip
(3.36 KiB) Downloaded 185 times

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3458
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: How to export revBrowserSnapshot to file?

Post by bn » Sat Oct 23, 2010 6:44 pm

Anybody on a Mac who could test above stack?
SnapFromBrowser-3.livecode.zip

Klaus?

regards
Bernd

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”