PDA

View Full Version : Inserting Web JPG into NR



GadgetBoy
February 12th, 2009, 06:22 AM
Is it possible to simply insert a JPG from a website onto a NR page?

I am looking to "paste" a weather map from Weather.com onto my weather page. Currently, I have to do it by inserting a browser window and then sizing it to my image. I still see a scroll bar on the right.

TIA
GB

dsmes
February 13th, 2009, 10:42 PM
Yes you can do this. Untested code follows. Put it in your CCFs Lua file in a function that you call when you want to get or refresh the image.
local url = "http://sirocco.accuweather.com/sat_mosaic_640x480_public/rs/isrNC.jpg"
local WxImage = socket.http.request(url)
NetRemote.SetImageVariable("Accuweather_Image", "image/jpg", WxImage)Now in your NR CCF, create a frame with an image variable name of Accuweather_Image. Good luck!

GadgetBoy
February 16th, 2009, 09:32 PM
I tried that and got an error (see attached).

dsmes
February 16th, 2009, 09:38 PM
Try adding the following line at the top of your CCFs Lua file-
require ("socket")

GadgetBoy
February 16th, 2009, 09:41 PM
I added the code above directly after my existing lua code (note that this is the first time I am editing the code).

Thanks!

...
--Add your Lua code below

local url = "http://sirocco.accuweather.com/sat_mosaic_640x480_public/rs/isrNC.jpg"
local WxImage = socket.http.request(url)
NetRemote.SetImageVariable("Accuweather_Image", "image/jpg", WxImage)

GadgetBoy
February 16th, 2009, 09:51 PM
I added the new code and got this error (see attached)

dsmes
February 16th, 2009, 10:00 PM
Try also adding

require ('socket.http')

GadgetBoy
February 16th, 2009, 10:07 PM
Same error.

I was supposed to add the two lines to the very top of the ccf file, correct?

dsmes
February 16th, 2009, 10:21 PM
I'm not sure why that didn't work so let me ask the standard questions...
What version of NR are you running?
Yes, those two lines would go at the top of the Lua file associated with your CCF. That is, if your CCF is WeatherTest.ccf the corresponding Lua file name is WeatherTest.lua where both are in the same directory. Is this how you have it set up?
You may also want to attach your Lua file. Maybe Rob can spot something later tonight when he signs on.

GadgetBoy
February 16th, 2009, 10:31 PM
Version 2.06.129

The name of my file is testccf.ccf and my lua file is testccf.lua

This is my entire lua file:

require ("socket")
require ('socket.http')

gacs = {}

local albumcount = 7;
local musiccount = 7;
local trackcount = 6;

local notifyTimer;

function HideNotifyMessage(myTimer)
notifyTimer:KillTimer();
notifyTimer = nil;
NetRemote.SetVariable('Notify.Show',0);
end;
function ShowNotifyMessage(msg)
if (notifyTimer ~= nil) then
notifyTimer:KillTimer();
notifyTimer = nil;
end;
NetRemote.SetVariable('Notify.Message',msg);
NetRemote.SetVariable('Notify.Show',1);
notifyTimer = NetRemote.SetTimer(2000,HideNotifyMessage);
end;
function VolumeChanged(varname,varvalue,handle)
print('Volume changed : '..varvalue);
ShowNotifyMessage('Volume: '..varvalue);
end;
function MuteChanged(varname,varvalue,handle)
if (varvalue == '1') then
ShowNotifyMessage('Mute On');
else
ShowNotifyMessage('Mute Off');
end;
end;
function TrackChanged(varname,varvalue,handle)
-- ShowNotifyMessage('Track Changed\n'..varvalue);
end;
NetRemote.RegisterVariableWatch('MP.Volume',Volume Changed);
NetRemote.RegisterVariableWatch('MP.MuteState',Mut eChanged);
NetRemote.RegisterVariableWatch('MP.Track',TrackCh anged);

function IsGACEntryPlayingNow(value,gaco,index)
return (tonumber(value) == gaco.start+index+1);
end;

--album list
gacs[0] = GAC:new{var='GAC[0]',includeSubItemCount=0,imageSize='N', fields='',count=albumcount, useGP=1};

--other music list
gacs[1] = GAC:new{var='GAC[1]',includeSubItemCount=0,imageSize='N', fields='',count=musiccount, useGP=1 };

--track list (from album)
gacs[2] = GAC:new{var='GAC[2]',includeSubItemCount=0,imageSize='N',fields='',co unt=trackcount, useGP=1 };

--dvd list
gacs[3] = GAC:new{var='GAC[3]',includeSubItemCount=0,imageSize='S',fields='',co unt=6, useGP=1 };

--video list
gacs[4] = GAC:new{var='GAC[4]',includeSubItemCount=0,imageSize='N',fields='File name',count=albumcount, useGP=1 };

--picture list
gacs[5] = GAC:new{var='GAC[5]',includeSubItemCount=0,imageSize='N',fields='File name',count=albumcount, useGP=1 };

--tv
gacs[6] = GAC:new{var='GAC[6]',includeSubItemCount=0,imageSize='N', fields='Date,Filename',count=musiccount, useGP=1 };

--playing now
gacs[8] = GAC:new{scheme='Playing Now',var='GAC[8]',includeSubItemCount=0,imageSize='N',fields='',co unt=musiccount, useGP = 1};
--Add your Lua code below

local url = "http://sirocco.accuweather.com/sat_mosaic_640x480_public/rs/isrNC.jpg"
local WxImage = socket.http.request(url)
NetRemote.SetImageVariable("Accuweather_Image", "image/jpg", WxImage)

dsmes
February 16th, 2009, 10:49 PM
Add a function around the code I posted earlier.
function GetWeatherMap()
local url = "http://sirocco.accuweather.com/sat_mosaic_640x480_public/rs/isrNC.jpg"
local WxImage = socket.http.request(url)
NetRemote.SetImageVariable("Accuweather_Image", "image/jpg", WxImage)
endNote the indenting of code inside a function... it makes things a bit more readable. Now, in your CCF, add a button and on the Action Designer tab, select NRBasic / Lua / "Execute lua code (OnRelease)" for the action, and for the lua code, add the line
GetWeatherMap();
I follow the line with a carriage return just to be sure. Now, when you press this button in your CCF, it will call the function that gets the image.

GadgetBoy
February 16th, 2009, 11:20 PM
Still no go - same error.

I attached the lua file - unfortunately, the ccf file is ~900k and I cannot upload.

Thanks for the help so far.

GB

dsmes
February 17th, 2009, 06:18 AM
If Rob doesn't spot something, I'll try and upload an example tonight.

Rob H
February 17th, 2009, 06:21 AM
I can't see anything obviously wrong there. Do you have socket_core.dll in your lualib folder?

Is this Win32 or PPC? If Win32 what locale are you using?

GadgetBoy
February 17th, 2009, 07:38 AM
I can't see anything obviously wrong there. Do you have socket_core.dll in your lualib folder?

Is this Win32 or PPC? If Win32 what locale are you using?

Yes, I have that file in my lualib folder.

Not sure of the question. I have NetRemote running on a Windows XP PC. I changed no directories when installing the software. I can forward the ccf file to you if you like. It's ~900K, so I can't attach it here.

Rob H
February 17th, 2009, 07:43 AM
You should be able to upload it here if you zip it.

By locale I meant are you using a non-English version of XP?

GadgetBoy
February 17th, 2009, 07:59 AM
Didn't realize there was a higher size restriction on .zip files.

As far as locale, I am in the US with an English version.

Thanks again,
GB

dsmes
February 18th, 2009, 08:35 PM
Hey GB,
I've attached an example that works for me. Note that the image is larger than the window it is displayed in. I think you asked about that in your original post. This allows you to "crop" large images to the area of interest. Hopefully it will work for you. If it doesn't, there may be something wrong with your NR install (I'm guessing). Let us know.

Solosid
February 19th, 2009, 02:45 PM
hey dsmes,


I have just tried that and changed your 'url' for GB's 'url' and it works fine for me.

cheers


Mark

dsmes
February 19th, 2009, 09:59 PM
Nothing like a good example to learn by... right?!
Actually, the Image Frame in my example is set up to receive a 700 x 700px image. If you changed the url to what was posted earlier, that's a 640 x 480 pixel image which i think would get stretched (distorted aspect ratio) to fit the 700 x 700 frame which then gets cropped by the outer frame. At any rate, I hope it works for GB and that we hear back from him.

GadgetBoy
February 20th, 2009, 06:19 AM
Ok, so it turns out that my install on the PC that I was testing this on was apparently corrupt; I reinstalled (the newest version) and your test ccf worked. I noticed with the

So, I went back to my ccf with your suggested changes and it worked as well.

Then I went to the other PC that I actually use to run the touchscreen for my setup and it wasn't showing the image, just "New Frame" with a box around it. I noticed I was running an old version of NR (2.0.0.95), so I immediately downloaded and installed the new version. Now it seems to be working.

Thanks for all the help guys... I am sure that I will be back for more assistance ;-)

GB

GadgetBoy
February 20th, 2009, 06:28 AM
;-)

So do I need to create separate functions for each image that I wish to have appear on my pages?

I understand that I will need to change the variable (i.e. Accuweather_Image). Is WxImage a variable?

Thanks again,
GB

GadgetBoy
February 20th, 2009, 07:06 AM
I am also having a new problem saving the properties for a button.

I right click on the button and select "Properties"

I go to "Action Designed"

I add go to "Execute lua code (on release)"

I add my function, "GetWeatherCurrentTemp();" plus carriage return in the code area.

I then add Jump to the page where the image will appear.

I save it and when I click on "Properties" again, the two lines I added are gone.

Any thoughts?

Rob H
February 20th, 2009, 07:15 AM
If you're using the latest NRD then use the properties pane that should be under the tree rather than the element properties window, that window is being phased out.

Rob H
February 20th, 2009, 07:17 AM
Nothing like a good example to learn by... right?!
Actually, the Image Frame in my example is set up to receive a 700 x 700px image. If you changed the url to what was posted earlier, that's a 640 x 480 pixel image which i think would get stretched (distorted aspect ratio) to fit the 700 x 700 frame which then gets cropped by the outer frame. At any rate, I hope it works for GB and that we hear back from him.

BTW if you use the very latest CCF format (1.1 rev 1.5) then you can change the image scaling to e.g. retain the aspect ratio

Solosid
February 20th, 2009, 10:44 AM
BTW if you use the very latest CCF format (1.1 rev 1.5) then you can change the image scaling to e.g. retain the aspect ratio

Hi Rob,

How do you know if your using 1.1rev1.5 ??

cheers

Mark

Rob H
February 20th, 2009, 11:12 AM
Right click on System in the tree and select Properties - you can tell from the drop down which revision you're using. You have to explicitly select rev 1.5 as it's still experimental, and only works with the latest build of NetRemote.

GadgetBoy
February 24th, 2009, 06:39 AM
Looks like everything is working now... However, I have come across images that can only be displayed in a browser:

http://tinyurl.com/bvhcu7

Any ideas?

GadgetBoy
February 24th, 2009, 06:40 AM
Ahh... Wait a sec. The image above is a .gif - do I need to change the function?

dsmes
February 24th, 2009, 07:49 AM
So do I need to create separate functions for each image that I wish to have appear on my pages?

I understand that I will need to change the variable (i.e. Accuweather_Image). Is WxImage a variable?You can have several functions or just one function that collects multiple images.
Ahh... Wait a sec. The image above is a .gif - do I need to change the function?You need to change the mime type to gif. i.e.
NetRemote.SetImageVariable("NR Image Name", "image/gif", WxImage)Regarding the http://tinyurl.com/bvhcu7 link, gifs with motion can only be displaye in a web browser. I typically write a mini web page to crop the motion image and get rid of the scroll bars. See post 4 here (http://www.promixis.com/forums/showthread.php?t=16645&highlight=radar) for example.