Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download image/png - RCurl

Tags:

http

r

rcurl

I'm trying to use Clearbit.com's free logo API (https://logo.clearbit.com/:domain) to download the a few company logos.

To try out the tool, simply paste https://logo.clearbit.com/nike.com into your web browser.

The goal is to save the Response from a GET request as a PNG file. Here is a an example of the code I'm using, which fails.

    library(RCurl)
    url <- "https://logo.clearbit.com/basf.com"
    png <- getURL(url, httpheader = "image/png", ssl.verifypeer = F)

This produces the following error message:

    Error in curlPerform(curl = curl, .opts = opts, .encoding = .encoding) : 
    embedded nul in string:'‰PNG\r\n\032\n\0\0\0\rIHDR\0\0\0\0\0\0\b\006\0\0\0Ã>aË\0\0\0\004gAMA\0\0±\vüa\005\0\0\0 cHRM\0\0z&\0\0€„\0\0ú\0\0\0€è\0\0u0\0\0ê`\0\0:˜\0\0\027pœºQ<\0\0\0\006bKGD\0ÿ\0ÿ\0ÿ ½§“\0\0\0\atIME\aß\006\036\022\0228_nn\005\0\0\027$IDATxÚíyx[Õ÷?÷^IW»dË–÷5v\026'qœ•¤$!%$¡P(]\030Z†y™2CK\aZ\006ž–ç-Ó…¶Ó>}g\nü¥lçi¡e:L\031\030(…°¦¤$$„fOììÞâ}·,YÒ]æ\017+"ŠäÄÄv3ɽŸ<y\022stîÑ9ß{öó;Â뇟Ô11,â…N€É…Å\024€Á1\005`pL\001\030\034S\0\006Ç\024€Á1\005`pL\001\030\034S\0\006Ç2•‘9­^<r\016ƒ£Œ*#IwQÈu•eüNgèxòÿ’hÁoÏG\024$B±>"ñá\v?—<S(\0êœË\bºËÙÛþ\026£§\025¬WΡ¶`mÆo½qd,œßžÇü‚µØ-®¤_W¨‘\003›Q´è…ΧK–I\vÀ#çà·ç‘ï©ÄïÈÏ\030ÆkÏ\005 y`?]¡¦4\177I´RW¸\036«dçP÷{Œ*#ÌÊ]NÐ]Žª)ìïÜt¡óé’eÒ\002(ò΢Ä_sÖ0.[\026\0ý‘\016ú#miþ9Î\022¬’þH;Í\003û\001\020\005‘ùùW’ç©à`×f4]M†\027\004‘ «\034€P¬‘Ø\00Ö„ä8K\023Ïj'¦FD+\005ž*|ö º®Ñ>|,-\r\016«—|Ï\f\\6?è:‘ø0¡ã„bý\0Ø-.|ö<¢Ê\b\021%D©\177. p¤g;N«—|O\025.›\017\035\030\036íáäÐዦ֚´\0:C'\bÇ\a\001(ñÏÅiõ¦…q'\004à°z¨+\\(XÆ\n»\177\037ª®$kˆS\031\0160\020é\004Æú\017n9›¡

I've searched through the documentation, but I have not been able to remedy this, so please advise.

P.S. This is my first post on stackoverflow, so feel free to pose suggestions on style and general guidelines.

Thanks, Ryan

like image 605
Ryan Erwin Avatar asked Dec 03 '25 09:12

Ryan Erwin


2 Answers

An alternative to RCurl is the new curl package of Jeroen Ooms, which provides a modern interface to libcurl.

## install.packages("curl")
library("curl")
curl_download(url = "https://logo.clearbit.com/basf.com",
              destfile = "~/foo.png")

This is the image I downloaded:

enter image description here

like image 93
Gavin Simpson Avatar answered Dec 05 '25 23:12

Gavin Simpson


Try this

library(RCurl)
url <- "https://logo.clearbit.com/basf.com"
png <- getBinaryURL(url, httpheader = "image/png", ssl.verifypeer = F) # download
writeBin(png, con = tf <- tempfile(fileext = ".png")) # save
shell.exec(tf) # open file on windows
like image 22
lukeA Avatar answered Dec 06 '25 01:12

lukeA