Jump to content


Photo

[resolved] Add dynamically generated image to ImageField

images google chart api

  • Please log in to reply
3 replies to this topic

#1 adamkiss

adamkiss

    Master of the universe

  • Moderators
  • 1,078 posts
  • 289

Posted 20 January 2012 - 11:10 AM

Hey all,

I'm trying to add dynamically generated Google Chart Image to image field, but... it doesn't work :)

  $imgSrc = 'https://chart.googleapis.com/chart?chs=920x200&cht=bvs&chd=t:0,7,0,0,4,0,0,0,0,0,0,1,0,0,0,1,2,0,0,0,7,11,4,0,3,4,2,4,6,1&chds=a&chm=B,eeeeee,0,0,0&chls=3&chco=222222'
  $page->images->add($imgSrc);

It fails with 'Exception: Unable to copy: ' and adds a bunch of data.

I've got two questions: How can I affect the filename of the file created [thus add some extension, for instance it's PNG file]. And more importantly, why doesn't this work? :D I know for a fact that URL adding works.

Edit: Actually, this is how I save this:
	$page->images->removeAll();
	$page->images->add($commitsGraphSrc); //it's an URL for google chart API
	$page->images->add($languagesGraphSrc); //another URL for gchart API
	$page->save();


#2 adamkiss

adamkiss

    Master of the universe

  • Moderators
  • 1,078 posts
  • 289

Posted 20 January 2012 - 11:48 AM

Okay, this is me being idiot; if you've tested your images with '&', be sure to switch back to '&'only. Thanks.

#3 ryan

ryan

    Hero Member

  • Administrators
  • 5,753 posts
  • 3102

  • LocationAtlanta, GA

Posted 20 January 2012 - 02:33 PM

Hey Adam, we cut out of the conference early and just made it back. There's a few issues with this URL that make it not compatible. First is that I'm not sure you can pull through https with a PHP stream (though not positive). Second is that there's nothing about that URL to indicate it's a file. ProcessWire isn't going to know what to do with it because there's no filename or extension. I think you'd have to find some other way to get this saved to a file and then import to ProcessWire from there.

#4 adamkiss

adamkiss

    Master of the universe

  • Moderators
  • 1,078 posts
  • 289

Posted 22 January 2012 - 05:53 PM

Hey Ryan, you probably misunderstood ;) I switched from generating the URL with '&' (HTML encoded ampersand) to '&' (ampersand only) and now it works. I pull the google image in, save the page, then do some renaming... and suddenly, I've got nicely named google charts :)





Also tagged with one or more of these keywords: images, google, chart, api

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users