Skip to content

Instantly share code, notes, and snippets.

@symisc
Last active March 28, 2021 02:11
Show Gist options
  • Save symisc/8a40377803c48eed436aecc4f54e83cb to your computer and use it in GitHub Desktop.
Save symisc/8a40377803c48eed436aecc4f54e83cb to your computer and use it in GitHub Desktop.
Upload a local image using the PixLab API - https://pixlab.io/cmd?id=store
<?php
/*
* PixLab PHP Client which is just a single class PHP file without any dependency that you can get from Github
* https://github.com/symisc/pixlab-php
*/
require_once "pixlab.php";
# Upload a local image to the remote https://pixlab.xyz storage server or your own S3 bucket depending on the configuration on the PixLab dashboard.
# Use the output link for other purposes such as processing via mogrify, drawrectangles, etc. or simply serving content.
# https://pixlab.io/cmd?id=store for more info.
$img_path = './locale_media_file.png';
/* Process */
$pix = new Pixlab('PIXLAB_API_KEY'); # PixLab API Key - Get yours from https://pixlab.io/dashboard
$pix->switch_to_http(); /* Switch to http for fast upload */
if( !$pix->post('store',array('comment' => 'Super Secret Image'),$img_path) ){
echo $pix->get_error_message()."\n";
die;
}
echo "Uploaded Pic Link: ".$pix->json->link."\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment