hoangweb
4/26/2018 - 1:38 PM

cloudinary php

<?php
include 'vendor/autoload.php';

\Cloudinary::config(array( 
  "cloud_name" => "sample", 
  "api_key" => "874837483274837", 
  "api_secret" => "a676b67565c6767a6767d6767f676fe1" 
));

/**
 * upload image
 */
\Cloudinary\Uploader::upload("/home/my_image.jpg", [
  //custom public ID instead of using the randomly generated one
  "public_id" => "john_doe_1001",
  //can be organized in folders
  "public_id" => "my_folder/my_sub_folder/my_name"
  //use the original name of the uploaded image file as its Public ID
  "use_filename" => TRUE,
  
  //transformations
  "width" => 1000, "height" => 1000, "crop" => "limit",
  //custom coordinates cropping and forcing format
  "x"  => 50, "y" => 80, 
  "crop" => "crop", "format" => "png",
  
  //assigned tags
  "tags" => array('special', 'for_homepage'),
  
]);

/*
Array
(
    [public_id] => sample
    [version] => 1312461204
    [width] => 864
    [height] => 576
    [format] => jpg
    [bytes] => 120253
    [url] => https://res.cloudinary.com/demo/image/upload/v1371281596/sample.jpg
    [secure_url] => https://res.cloudinary.com/demo/image/upload/v1371281596/sample.jpg
)
*/
# or a public HTTP URL
\Cloudinary\Uploader::upload("http://www.example.com/image.jpg", [
  "public_id" => "sample_id",
   "crop" => "limit", "width" => "2000", "height" => "2000",
   "eager" => array(
     array( "width" => 200, "height" => 200, 
            "crop" => "thumb", "gravity" => "face",
            "radius" => 20, "effect" => "sepia" ),
     array( "width" => 100, "height" => 150, 
            "crop" => "fit", "format" => "png" )
   ),                                     
   "tags" => array( "special", "for_homepage" )
]);


//where images are uploaded by users of your PHP application through a web form
\Cloudinary\Uploader::upload($_FILES["file"]["tmp_name"]);

//any other file format
//or: "resource_type" => "auto"
\Cloudinary\Uploader::upload("sample_spreadsheet.xls", 
                             array("public_id" => "sample_spreadsheet",
                                   "resource_type" => "raw"));

/**
 * Change image
*/
//rename image
\Cloudinary\Uploader::rename('old_name', 'new_name');
\Cloudinary\Uploader::rename('old_name', 'new_name', array("overwrite" => TRUE));

//assign tags
\Cloudinary\Uploader::add_tag('another_tag', 
                              array('<public_id>', 'de9wjix4hhnqpxixq6cw'));

//clears the given tag from a list of images
\Cloudinary\Uploader::remove_tag('another_tag',
                                array('sample_id', 'de9wjix4hhnqpxixq6cw'));


/**
 * delete image
*/
//given public_id
\Cloudinary\Uploader::destroy('zombie');