seregazhuk / php-pinterest-bot

This PHP library will help you to work with your Pinterest account without using any API account credentials.
MIT License
416 stars 129 forks source link

Request: base64 Image #332

Closed razza-guhl closed 6 years ago

razza-guhl commented 6 years ago

Hi,

Is it possible to use an base64 encoded image for creating a pin? Currently URL and local file is supported.

$pinInfo = $bot->pins->create('http://exmaple.com/image.jpg', $boardId, 'Pin description');

Thank you

seregazhuk commented 6 years ago

Hi, I'm not sure. But what is your use-case? Why you can't use url or local file?

razza-guhl commented 6 years ago

I need to edit some images on the fly, pin them and throw the image away.

Local file method required the file physically exists on storage. But thats not necessary, all data are already in RAM and could be bypass directly.

Maybe PHP tmpfile() could be used in this case?

seregazhuk commented 6 years ago

I see. Actually, I don't want to add functionality to bot for such rare use-case. Bot is built to emulate site behavior and there is no way to create a pin from image stored in memory. I can suggest you to create a temporary file, flush image data to it, create a pin from this local file, then remove it:

$tempFile = tempnam(__DIR__, 'temp_image');
file_put_contents($tempFile, $imageData);
$bot->pins->create($tempFile, $boardId, $description);
unlink($tempFile);

What do you think?

razza-guhl commented 6 years ago

I understand, no problem. I'm going to use a temp file. Thanks for your suggestion!