View external image in htmltext?

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Garrett
Posts: 386
Joined: Sat Apr 08, 2006 8:15 am
Contact:

View external image in htmltext?

Post by Garrett » Mon Feb 16, 2009 11:26 pm

I'm having another old man brain fart here... is it possible and how do I reference an external image in html text?

Thanks,
~Garrett

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Tue Feb 17, 2009 6:21 am

You can use an online URL; as an example:

Code: Select all

set the imagesource of word 2 of field 1 to "http://forums.runrev.com/phpBB2/templates/subSilver/images/logo_phpBB.gif"
should display the Revolution forums logo in your field.

But it looks like a 'file://" URL doesn't work - so my next best bet is to create an image control, which references the file on disk, and then use the short id of this image control in your imageSource.

HTH,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

Garrett
Posts: 386
Joined: Sat Apr 08, 2006 8:15 am
Contact:

Post by Garrett » Tue Feb 17, 2009 6:46 am

K, thanks a lot Jan. I was trying to keep from having to add the images to the stack, but looks like I'll have to.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Tue Feb 17, 2009 10:07 am

Hi Jan,

What about "binfile:<path to file>"?

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Tue Feb 17, 2009 9:33 pm

Mark, your suggestion was spot-on. The following script did work for both remote and local URL's:

Code: Select all

on mouseUp
   set the imagesource of char 1 of word 1 of field 1 to "http://forums.runrev.com/phpBB2/templates/subSilver/images/logo_phpBB.gif"
   answer file "Select an image"
   set the imagesource of char 1 of word 2 of field 1 to ("binfile://" & it)
end mouseUp
The surprise part was in the fact that the local URL is different from how you'd refer to a file from a browser - of course, in reflection it makes sense that it needs to read the file as binary data, and the doc example does mention "binfile:" - but it's non-intuitive if you're used to html.

Ah well, you learn something new every day :-)

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

SparkOut
Posts: 2949
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Tue Feb 17, 2009 9:50 pm

If you're trying to do this by setting the htmlText to <img src="~path~"> can the same approach be adopted? I had a play with various permutations (including similarly to those mentioned above) and couldn't do it unless I referenced the image by id or by full http:// path. I couldn't get any version of file:// or binfile: etc to work with htmlText. (On Windows XP).

Garrett
Posts: 386
Joined: Sat Apr 08, 2006 8:15 am
Contact:

Post by Garrett » Tue Feb 17, 2009 10:28 pm

Well, I just did this and it works as I needed:

Code: Select all

<img src="binfile:C:\Projects\Graphics\image.png">
Then I load the html page into my rev program and the image is there.

SparkOut
Posts: 2949
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Tue Feb 17, 2009 11:07 pm

Flub! and yay! Doesn't even need to convert the spaces in the path either! I don't know what I was doing wrong before.
Thanks all.

Garrett
Posts: 386
Joined: Sat Apr 08, 2006 8:15 am
Contact:

Post by Garrett » Wed Feb 18, 2009 6:35 am

The drawback is though, that you have to use a full file path. Relative paths will not work.

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

Post by Klaus » Wed Feb 18, 2009 12:11 pm

Another drawback:
This is so counterintuitive and definitively not anything one would think of compared to the common HTML syntax.

Post Reply