Create Image Resource from Variable - NOT From File

pr0gr4mm3r's picture

He has: 1,502 posts

Joined: Sep 2006

PHP's imagecreatefromjpeg() function takes a image file name. It opens it, and loads it into an image resource. I need to load an image from somewhere on the web. URL file-access is disabled on my server, so I have to download it into memory using something like cURL.

So what I do is load the graphic into a variable, but the problem is that I can't find a way to convert that binary image data in the variable to an image resource. imagecreatefromjpeg() will only accept a file name. Am I missing something here? How do I take binary image data in a variable and load it into an image resource?

(Yes, saving it to a file and then loading it works, but why involve the file system when we don't have to?)

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

pr0gr4mm3r's picture

He has: 1,502 posts

Joined: Sep 2006

Darn it...I was thinking it was that simple. Thanks. Smiling

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.