<?php

require_once __DIR__ . '/inc/wixmedia-php/wix/media/WixClient.php';
$end_point = 'media.wixapps.net';
$api_key = "wix-a091529b-0151-4768-a83e-4cb899c90de2";
$secret = "d0f8172137974a83a27bfaf00af7da20";
$client = new WixClient($api_key, $secret);
$req_base64 = $_REQUEST['base64'];
if (empty($req_base64)) {
    die('no base64 string is provided');
}
$ini_val = ini_get('upload_tmp_dir');
$upload_tmp_dir = $ini_val ? $ini_val : sys_get_temp_dir();
$base64 = explode(',', $req_base64);
$file = $upload_tmp_dir . '/' . uniqid() . '.' . get_string_between($base64[0], '/', ';');
$success = file_put_contents($file, base64_decode($base64[1]));
$image = $client->uploadImage($file);
if (!empty($image)) {
    $meta = (array) $image->getMetadata();
    $url = $image->fit($meta['width'], $meta['height'])->getUrl();
    echo json_encode($meta + array('url' => $url));
}
unlink($file);
function get_string_between($string, $start, $end)
{
    $string = ' ' . $string;
    $ini = strpos($string, $start);
    if ($ini == 0) {
        return '';
    }
    $ini += strlen($start);
 public function checkCredentials($api_key, $secret)
 {
     $source_sdk = __DIR__ . '/inc/wixmedia-php/wix/media/';
     require_once $source_sdk . 'WixClient.php';
     $client = new WixClient($api_key, $secret);
     return (bool) $client->getAuth()->getToken();
 }
Beispiel #3
0
<?php

$source_dir = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'wix' . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR;
require $source_dir . 'WixClient.php';
$api_key = 'wix-a091529b-0151-4768-a83e-4cb899c90de2';
$secret = 'd0f8172137974a83a27bfaf00af7da20';
$client = new WixClient($api_key, $secret);
/*if ($image = $client->uploadImage('test.jpg')) {
	echo 'The image was successfully uploaded!';
	echo '<br>';
	echo $image->getId();
	echo '<br>';
	echo '<pre>'.print_r($image->getMetadata(), true).'</pre>';
} else {
	echo 'An error occurred, check your php log file for more information.' ."\n";
	echo 'Trying to use stock image...' ."\n";
	$image_id = 'wixmedia-samples/images/cdf1ba9ec9554baca147db1cb6e011ec/parrot.jpg';
	$image = $client->getImageById($image_id);
	echo $image->getId();
}
*/
$image_id = 'wixmedia-samples/images/cdf1ba9ec9554baca147db1cb6e011ec/parrot.jpg';
$image = $client->getImageById($image_id);
print $image->fit(420, 420)->negate()->getUrl();
/*echo $image->canvas(400, 800, 'top', 'cccccc')->getUrl();
echo '<br>';

$image->reset();
echo $image->fill(480, 240)->getUrl();
echo '<br>';
<?php

$source_dir = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'wix' . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR;
require $source_dir . 'WixClient.php';
$api_key = 'YOUR_API_KEY';
$secret = 'YOUR_API_SECRET';
$client = new WixClient($api_key, $secret);
if ($image = $client->uploadImage('test.jpg')) {
    echo "The image was successfully uploaded!\n";
    echo $image->getId();
} else {
    echo "An error occurred, check your php log file for more information.\n";
    echo "Trying to use stock image...\n";
    $image_id = 'wixmedia-samples/images/cdf1ba9ec9554baca147db1cb6e011ec/parrot.jpg';
    $image = $client->getImageById($image_id);
    echo $image->getId();
    echo "\n";
}
echo $image->canvas(400, 800, 'top', 'cccccc')->getUrl();
echo '<br>';
$image->reset();
echo $image->fill(480, 240)->getUrl();
echo '<br>';
$image->reset();
echo $image->fit(480, 240, 'Lanczos2SharpFilter')->getUrl();
echo '<br>';
$image->reset();
echo $image->crop(1900, 800, 800, 900)->getUrl();
echo '<br>';
$image->reset();
echo $image->fit(120, 120)->adjust(10, -15)->getUrl();