generate_transformation_string() public static method

Warning: $options are being destructively updated!
public static generate_transformation_string ( &$options = [] )
Example #1
0
 protected static function build_responsive_breakpoints($breakpoints)
 {
     if (!$breakpoints) {
         return NULL;
     }
     $breakpoints_params = array();
     foreach (\Cloudinary::build_array($breakpoints) as $breakpoint_settings) {
         if ($breakpoint_settings) {
             $transformation = \Cloudinary::option_consume($breakpoint_settings, "transformation");
             if ($transformation) {
                 $breakpoint_settings["transformation"] = \Cloudinary::generate_transformation_string($transformation);
             }
             array_push($breakpoints_params, $breakpoint_settings);
         }
     }
     return json_encode($breakpoints_params);
 }
Example #2
0
 public static function build_eager($transformations)
 {
     $eager = array();
     foreach (\Cloudinary::build_array($transformations) as $trans) {
         $transformation = $trans;
         $format = \Cloudinary::option_consume($transformation, "format");
         $single_eager = implode("/", array_filter(array(\Cloudinary::generate_transformation_string($transformation), $format)));
         array_push($eager, $single_eager);
     }
     return implode("|", $eager);
 }
Example #3
0
 public static function zip_download_url($tag, $options = array())
 {
     $params = array("timestamp" => time(), "tag" => $tag, "transformation" => \Cloudinary::generate_transformation_string($options));
     $params = Cloudinary::sign_request($params, $options);
     return Cloudinary::cloudinary_api_url("download_tag.zip", $options) . "?" . http_build_query($params);
 }
Example #4
0
 public static function cloudinary_url($source, &$options = array())
 {
     $type = Cloudinary::option_consume($options, "type", "upload");
     if ($type == "fetch" && !isset($options["fetch_format"])) {
         $options["fetch_format"] = Cloudinary::option_consume($options, "format");
     }
     $transformation = Cloudinary::generate_transformation_string($options);
     $resource_type = Cloudinary::option_consume($options, "resource_type", "image");
     $version = Cloudinary::option_consume($options, "version");
     $format = Cloudinary::option_consume($options, "format");
     $cloud_name = Cloudinary::option_consume($options, "cloud_name", Cloudinary::config_get("cloud_name"));
     if (!$cloud_name) {
         throw new InvalidArgumentException("Must supply cloud_name in tag or in configuration");
     }
     $secure = Cloudinary::option_consume($options, "secure", Cloudinary::config_get("secure"));
     $private_cdn = Cloudinary::option_consume($options, "private_cdn", Cloudinary::config_get("private_cdn"));
     $secure_distribution = Cloudinary::option_consume($options, "secure_distribution", Cloudinary::config_get("secure_distribution"));
     $cdn_subdomain = Cloudinary::option_consume($options, "cdn_subdomain", Cloudinary::config_get("cdn_subdomain"));
     $cname = Cloudinary::option_consume($options, "cname", Cloudinary::config_get("cname"));
     $original_source = $source;
     if (!$source) {
         return $original_source;
     }
     if (preg_match("/^https?:\\//i", $source)) {
         if ($type == "upload" || $type == "asset") {
             return $original_source;
         }
         $source = Cloudinary::smart_escape($source);
     } else {
         if ($format) {
             $source = $source . "." . $format;
         }
     }
     if ($secure && !$secure_distribution) {
         if ($private_cdn) {
             throw new InvalidArgumentException("secure_distribution not defined");
         } else {
             $secure_distribution = Cloudinary::SHARED_CDN;
         }
     }
     if ($secure) {
         $prefix = "https://" . $secure_distribution;
     } else {
         $crc = crc32($source);
         if ($crc < 0) {
             $crc += 4294967296;
         }
         $subdomain = $cdn_subdomain ? "a" . (fmod($crc, 5) + 1) . "." : "";
         $host = $cname ? $cname : ($private_cdn ? $cloud_name . "-" : "") . "res.cloudinary.com";
         $prefix = "http://" . $subdomain . $host;
     }
     if (!$private_cdn) {
         $prefix .= "/" . $cloud_name;
     }
     return preg_replace("/([^:])\\/+/", "\$1/", implode("/", array($prefix, $resource_type, $type, $transformation, $version ? "v" . $version : "", $source)));
 }
Example #5
0
 protected function transformation_string($transformation)
 {
     return is_string($transformation) ? $transformation : Cloudinary::generate_transformation_string($transformation);
 }
 /**
  * should support and translate operators: '=', '!=', '<', '>', '<=', '>=', '&&', '||'
  * and variables: width, height, pages, faces, aspect_ratio
  */
 public function test_translate_if()
 {
     $allOperators = 'if_' . 'w_eq_0_and' . '_h_ne_0_or' . '_ar_lt_0_and' . '_pc_gt_0_and' . '_fc_lte_0_and' . '_w_gte_0' . ',e_grayscale';
     $condition = "width = 0 && height != 0 || aspect_ratio < 0 && page_count > 0 and face_count <= 0 and width >= 0";
     $options = array("if" => $condition, "effect" => "grayscale");
     $transformation = Cloudinary::generate_transformation_string($options);
     $this->assertEquals($allOperators, $transformation);
     $this->assertEquals(array(), $options);
     $options = array("if" => "aspect_ratio > 0.3 && aspect_ratio < 0.5", "effect" => "grayscale");
     $transformation = Cloudinary::generate_transformation_string($options);
     $this->assertEquals("if_ar_gt_0.3_and_ar_lt_0.5,e_grayscale", $transformation);
     $this->assertEquals(array(), $options);
 }
Example #7
0
 /**
  * Prepare streaming profile parameters for API calls
  * @param $options the options passed to the API
  * @return array A single profile parameters
  */
 protected function prepare_streaming_profile_params($options)
 {
     $params = $this->only($options, array("display_name"));
     if (isset($options['representations'])) {
         $array_map = array_map(function ($representation) {
             return array("transformation" => \Cloudinary::generate_transformation_string($representation));
         }, $options['representations']);
         $params["representations"] = json_encode($array_map);
     }
     return $params;
 }