URL to JPG

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
ARAS
Posts: 55
Joined: Sat Nov 02, 2013 5:35 pm

URL to JPG

Post by ARAS » Sat Nov 09, 2013 11:58 am

Hi,

How can I get the snapshots of an URL list which is in Text Field?

ARAS

Traxgeek
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 281
Joined: Wed Jan 09, 2013 10:11 am

Re: URL to JPG

Post by Traxgeek » Sat Nov 09, 2013 12:06 pm

Hi ARAS,

Give us example of the text field ?

In the absence of such, I would do something like :
-1- get the number of lines in the field (number of lines),
-2- cycle through each one (repeat loop),
-3- put each line into a temporary variable (put line x of myField into)
-4- update the image pointer with image pointed to by the temporary variable (set the filename of image "..." to...)
and do it all again until each line has been handled

Would that make sense or have I misunderstood ?

HTH

EDIT : this Tutorial maybe of help ? : http://lessons.runrev.com/s/3527/m/4603 ... ing-images
Regards
I'm 'getting there'... just far too slowly !
Mac (Siera) and PC (Win7)
LiveCode 8.1.2 / 7.1.1

ARAS
Posts: 55
Joined: Sat Nov 02, 2013 5:35 pm

Re: URL to JPG

Post by ARAS » Sat Nov 09, 2013 12:22 pm

Hi Traxgeek,

Let's say the code below is the content of my text field called "URLs".

Code: Select all

www.google.com
www.livecode.com
www.runrev.com
When I click a button called "URLtoJPG", I want to get the snapshots of websites.

I prefer it to be on the background while taking snapshots but can also be like - a browser opens the URL and takes the snapshot of it and repeats it for the next URL

I didn't get the number 4, but I think I want to do sth similar.

Thanks,
ARAS

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: URL to JPG

Post by Klaus » Sat Nov 09, 2013 2:11 pm

Hi ARAS,
ARAS wrote: When I click a button called "URLtoJPG", I want to get the snapshots of websites.
I prefer it to be on the background while taking snapshots but can also be like -
a browser opens the URL and takes the snapshot of it and repeats it for the next URL...
That's the way to go!

Open the URL in a browser object one after another and use "revBrowserSnapshot" to create a JPG from the sites.
Read up "revBrowserSnapshot" and everything you need to create a browser object in the dictionary.


Best

Klaus

ARAS
Posts: 55
Joined: Sat Nov 02, 2013 5:35 pm

Re: URL to JPG

Post by ARAS » Sat Nov 09, 2013 4:20 pm

Hi Klaus,

Code: Select all

local tSnapshot
revBrowserSnapshot sBrowserId, "tSnapshot"
set the imageData of image "Browser Thumbnail" to tSnapshot
Where can I see my browser id? I am using OS X.

Thanks,
ARAS

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: URL to JPG

Post by Klaus » Sat Nov 09, 2013 4:48 pm

Hi ARAS,

you need to open a new browser object first!
Check "revbrowseropen" in the dictionary and this tutorial:
http://lessons.runrev.com/s/lessons/m/4 ... pdf-in-rev

Could not find any other REVBROWSER example on the Livecode site :(


Best

Klaus

ARAS
Posts: 55
Joined: Sat Nov 02, 2013 5:35 pm

Re: URL to JPG

Post by ARAS » Sun Nov 10, 2013 2:54 pm

Hi Klaus,

I was able to browse a website in an Image Area with this code.
One thing I have noticed was that tBrowserId always changes when ever I click the button. Why? Is that because I always create a new one whenever I click the button? By the way, do you know how to reset an image area?

Code: Select all

on mouseUp
   get revBrowserOpen(the windowId of this stack, "http://www.google.com") 
   if it is an integer then
      put it into tBrowserId
     revBrowserSet tBrowserId, "rect", the rect of image "Image"
   else
      answer "There was an error: " && it  --if the browser doesn't start, show the error. 
   end if
--answer tBrowserId
end mouseUp
I was trying to capture that image area, but I am failed. I used the code below, but it always created a black png not the browser snapshot. Do you know what's wrong with the code?

Code: Select all

on mouseUp
   get revBrowserOpen(the windowId of this stack, "http://www.google.com") 
     if it is an integer then
            put it into gBrowserID

    put empty into myImgData
    revBrowserSnapShot gBrowserID,"myImgData"
    set the imagedata of img 1 to myImgData
    set the width of img 1 to the formattedWidth of img 1
    set the height of img 1 to the formattedheight of img 1
    put specialfolderpath("desktop") & \
    "/rev snapshot.png" into myFile
    set the filetype to "????PNGf"
    export img 1 to file myFile as PNG
  end if
end mouseUp
Also can you explain what this line does?

Code: Select all

     revBrowserSet tBrowserId, "rect", the rect of image "Image"
In the dictionary, it says "• rect - Returns the rect of the browser relative to the parent window. The default rect is 0,0,0,0."
Is it adjusting the webpage size according to the image area size?

ARAS

Traxgeek
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 281
Joined: Wed Jan 09, 2013 10:11 am

Re: URL to JPG

Post by Traxgeek » Sun Nov 10, 2013 4:32 pm

Hi ARAS,

Been away for a bit. Just looking at your progress.

I'll go take a look now. In the meantime :

'put empty into image "MyImage" '

should give you a cleared / empty image..

Back in a bit...
I'm 'getting there'... just far too slowly !
Mac (Siera) and PC (Win7)
LiveCode 8.1.2 / 7.1.1

ARAS
Posts: 55
Joined: Sat Nov 02, 2013 5:35 pm

Re: URL to JPG

Post by ARAS » Sun Nov 10, 2013 5:19 pm

Traxgeek wrote:Hi ARAS,

Been away for a bit. Just looking at your progress.

I'll go take a look now. In the meantime :

'put empty into image "MyImage" '

should give you a cleared / empty image..

Back in a bit...
Wow thanks Traxgeek,

I thought I tried that. I must have missed something.

It worked I can clear the image now. Thank you.

ARAS

Traxgeek
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 281
Joined: Wed Jan 09, 2013 10:11 am

Re: URL to JPG

Post by Traxgeek » Sun Nov 10, 2013 5:23 pm

OK, I'm back... I knew I'd struggled with this for quite some time :oops: but eventually got results :D

As I recall a lot of the example stuff was sheer tosh ! Which resulted in much frustration - But...

In no small measure due to the Forum here (especially Bernd - a thousand thankyous Bernd ! ) and various other Google searches, I managed to succeed - so keep on going - it's worth the pain in the end ! Anyway, during my searches and coding I saved a load of examples; the most useful for you at the moment (I think) being Bernd's 'SnapFromBrowser' project.

Here's the link I saved (seems to still be available): http://ftp.runrev.com/forums/viewtopic. ... 86&p=28183 (half way down the page).
Don't forget to thank Bernd for his troubles !

I have other example stacks and my own stack (which would be a little too large / convoluted to extract, hence Bernd's) if you need more help....

HTH

Regards.
I'm 'getting there'... just far too slowly !
Mac (Siera) and PC (Win7)
LiveCode 8.1.2 / 7.1.1

ARAS
Posts: 55
Joined: Sat Nov 02, 2013 5:35 pm

Re: URL to JPG

Post by ARAS » Sun Nov 10, 2013 5:52 pm

Thank you Traxgeek for helping me,

I will take a look at it in a minute.

By the way,

Code: Select all

put empty into image "Image"
This code stopped working. I think that's why I wasn't able to clear when I tried before.
In the Image Area, I have revBrowser running a webpage. Is that why?

I have seen closeRevBrowser in the dictionary. Is it doing the same thing. Is it clearing the image field?

I tried the code below but couldn't see any difference.

Code: Select all

    get revBrowserOpen (the windowId of this stack) 
   put it into tBrowserId
   revBrowserClose tBrowserId
ARAS

ARAS
Posts: 55
Joined: Sat Nov 02, 2013 5:35 pm

Re: URL to JPG

Post by ARAS » Sun Nov 10, 2013 6:13 pm

I have download the stack of Bernd. It is awesome. Thanks to Bernd for its awesome stack :)
I will try to learn from there. :o The only thing missing is to save the snapshot into a file, and actually I want to snapshot everything on the webpage-not just the things shown in the image area. You know webpages doesn't fit into Image Area all the time.

Thanks,
ARAS

Traxgeek
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 281
Joined: Wed Jan 09, 2013 10:11 am

Re: URL to JPG

Post by Traxgeek » Sun Nov 10, 2013 8:35 pm

Hi ARAS,

You could 'export as file' or simply save the image...

I have never tried to grab more of a wesite page than the area I can see in one stack card/ image. I hid the browser control during the grab process so made it pretty large.

I'm away from my desk at the moment but could continue this tomorrow if you like.
Last edited by Traxgeek on Mon Nov 11, 2013 9:41 am, edited 1 time in total.
I'm 'getting there'... just far too slowly !
Mac (Siera) and PC (Win7)
LiveCode 8.1.2 / 7.1.1

ARAS
Posts: 55
Joined: Sat Nov 02, 2013 5:35 pm

Re: URL to JPG

Post by ARAS » Sun Nov 10, 2013 9:01 pm

Hi Traxgeek,

I was able to export it as a file by adding the code below into takesnapshot button. Just incase sb is interested, I put it down.

Code: Select all

   set the text of img "thumbnail" to tImgData
   wait 10 milliseconds with messages
   set the resizeQuality of img "thumbnail" to "best"
   
   put specialfolderpath("desktop") & \
    "/rev snapshot.png" into tImgData
    set the filetype to "????PNGf"
    export img 1 to file tImgData as PNG
I am not in hurry Traxgeek. I would love to learn from you. Anytime you want :)
Thanks,
ARAS

Post Reply