Cannot get an ico file from the web and use it as an image f

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

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Post Reply
mrcoollion
Posts: 450
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Cannot get an ico file from the web and use it as an image f

Post by mrcoollion » Fri Jul 08, 2016 12:30 pm

I cannot get an ico file from the web and use it as an image for a button.
Tried everything i could think of and researched but i cannot get it working.
Code works fine with jpg files but not with an ico file.

I use the code below and I have also attached a test stack for those interested.

Any idea's ?

Code: Select all

on mouseUp
   --- reset all ---
   put empty into field "Result"
   set the text of img "WebSiteIcon" to empty
   set the icon of button "ShowIconOnButton" to 0
   --- end reset ---
   if the icon of button "ShowIconOnButton" is 0 then
      put field"TheWebsiteURL" into TheWebsiteURL
      if TheWebsiteURL is not empty then
         put  TheWebsiteURL & "/favicon.ico" into TheWebsiteIconURL // if you place /favicon.ico behind a site 9base) urel then you should get the site icon.
         --------------------------------------------------------------------------------------
         --import  from file TheWebsiteIconURL
         --put last  image  into  img "WebSiteIcon" 
         --DELETE last  image 
         --------------------------------------------------------------------------------------
         --put URL TheWebsiteIconURL into  img "WebSiteIcon" 
         --------------------------------------------------------------------------------------
         load URL TheWebsiteIconURL with message "FileIsDoneDownloading"
         --------------------------------------------------------------------------------------
         --set the filename of img "WebSiteIcon" to TheWebsiteIconURL
         ---------------------------------------------------------------------------------------
         if img "WebSiteIcon" is not empty then // because it does not work the image stay empty and therefor i need this.
            set the width of image  img "WebSiteIcon" to the width of button "ShowIconOnButton"
            set the height of image  img "WebSiteIcon" to the height of button "ShowIconOnButton"
            set the icon of button "ShowIconOnButton" to the id of img "WebSiteIcon" 
         end if
      end if
   end if
end mouseUp

on FileIsDoneDownloading pURL, pURLStatus
   if pURLStatus is "cached" then
      ## Revolution has cached URL content. Accessing the url uses the cache.
      set the text of img "WebSiteIcon" to URL pURL
      --put URL pURL into  img "WebSiteIcon" 
      ## Remove URL from cache if you are all done with it.
      unload url pURL
   else
      put libURLErrorData(pURL) into theError
      set the text of field "Result" to "An error occurred:" && theError & "."
   end if
end FileIsDoneDownloading
Attachments
ProblemIconFromWebToButton.zip
Problem to get ico file from web into a button
(1.52 KiB) Downloaded 48 times

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

Re: Cannot get an ico file from the web and use it as an ima

Post by Klaus » Fri Jul 08, 2016 1:03 pm

Hi mrcocollion,

1. this line:

Code: Select all

...
set the icon of button "ShowIconOnButton" to 0
--- end reset ---
Makes the next line (and the whole IF END IF clause) completely obsolete! :D

Code: Select all

...
if the icon of button "ShowIconOnButton" is 0 then
...
2. Livecode does not support the image format ICO, although the term "button ICON" lets you think so!
That will explain this:
Code works fine with jpg files but not with an ico file.
And no, I don't have any idea how (or if at all) LC can convert ICO to any other supported image format.


Best

Klaus

mrcoollion
Posts: 450
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Cannot get an ico file from the web and use it as an ima

Post by mrcoollion » Fri Jul 08, 2016 9:47 pm

Thanks Klaus :D ,

I kept on trying anyway but did not succeed :cry:

It is a bummer that this is tot possible because especially for the internet it would be nice to get the ico images from a site to show these on an button or for other reasons.

Kind regards,

Paul

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7299
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Cannot get an ico file from the web and use it as an ima

Post by FourthWorld » Fri Jul 08, 2016 10:27 pm

I wish I had a couple hours to spare - looks like it wouldn't be too hard to parse out the BMP/PNG data from the ICO file:
https://en.wikipedia.org/wiki/ICO_(file_format)
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

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

Re: Cannot get an ico file from the web and use it as an ima

Post by Mark » Sat Jul 09, 2016 8:16 am

Hi,

A long time ago, we made an external for Windows to read ico files: http://www3.economy-x-talk.com/file.php ... g-external

We also have a library for Mac, which displays icns files. Our goal was to be able to display the icon of apps and files in LiveCode. We use it in Installer Maker.

Kind regards,

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

mrcoollion
Posts: 450
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Cannot get an ico file from the web and use it as an ima

Post by mrcoollion » Sat Jul 09, 2016 11:46 am

Thanks for the information Mark,

Regards,

Paul

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7299
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Cannot get an ico file from the web and use it as an ima

Post by FourthWorld » Sun Jul 10, 2016 12:26 am

I asked about image extraction from ICO files on the discussion list, and my friend Ken Ray sent me a stack to share here. When I asked him about license terms he wrote: "No licensing or terms - basically 'use for any purpose, anywhere'" - enjoy.
Attachments
Icon Loader.livecode.zip
(22.68 KiB) Downloaded 64 times
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

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

Re: Cannot get an ico file from the web and use it as an ima

Post by richmond62 » Sun Jul 10, 2016 3:58 pm

GIMP can also extract ICO files and export them in many, many formats:

https://www.gimp.org/downloads/

mrcoollion
Posts: 450
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Cannot get an ico file from the web and use it as an ima

Post by mrcoollion » Mon Jul 11, 2016 9:10 am

Thanks Richard (FourthWorld) and Ken :D

Great example stack.

regards,

Paul

Post Reply

Return to “Talking LiveCode”