build_array() public static method

public static build_array ( $value )
Example #1
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 #2
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 #3
0
 public static function generate_transformation_string(&$options = array())
 {
     $generate_base_transformation = array("Cloudinary", "generate_base_transformation");
     if ($options == array_values($options)) {
         return implode("/", array_map($generate_base_transformation, $options));
     }
     $size = Cloudinary::option_consume($options, "size");
     if ($size) {
         list($options["width"], $options["height"]) = preg_split("/x/", $size);
     }
     $width = Cloudinary::option_get($options, "width");
     $height = Cloudinary::option_get($options, "height");
     $has_layer = Cloudinary::option_get($options, "underlay") || Cloudinary::option_get($options, "overlay");
     if ($width && (floatval($width) < 1 || $has_layer)) {
         unset($options["width"]);
     }
     if ($height && (floatval($height) < 1 || $has_layer)) {
         unset($options["height"]);
     }
     $angle = implode(Cloudinary::build_array(Cloudinary::option_consume($options, "angle")), ".");
     $crop = Cloudinary::option_consume($options, "crop");
     if (!$crop && !$has_layer) {
         $width = $height = NULL;
     }
     $background = Cloudinary::option_consume($options, "background");
     if ($background) {
         $background = preg_replace("/^#/", 'rgb:', $background);
     }
     $base_transformations = Cloudinary::build_array(Cloudinary::option_consume($options, "transformation"));
     if (count(array_filter($base_transformations, "is_array")) > 0) {
         $base_transformations = array_map($generate_base_transformation, $base_transformations);
         $named_transformation = "";
     } else {
         $named_transformation = implode(".", $base_transformations);
         $base_transformations = array();
     }
     $effect = Cloudinary::option_consume($options, "effect");
     if (is_array($effect)) {
         $effect = implode(":", $effect);
     }
     $border = Cloudinary::option_consume($options, "border");
     if (is_array($border)) {
         $border_width = Cloudinary::option_get($border, "width", "2");
         $border_color = preg_replace("/^#/", 'rgb:', Cloudinary::option_get($border, "color", "black"));
         $border = $border_width . "px_solid_" . $border_color;
     }
     $flags = implode(Cloudinary::build_array(Cloudinary::option_consume($options, "flags")), ".");
     $params = array("w" => $width, "h" => $height, "t" => $named_transformation, "c" => $crop, "b" => $background, "e" => $effect, "bo" => $border, "a" => $angle, "fl" => $flags);
     $simple_params = array("x" => "x", "y" => "y", "r" => "radius", "d" => "default_image", "g" => "gravity", "q" => "quality", "p" => "prefix", "l" => "overlay", "u" => "underlay", "f" => "fetch_format", "dn" => "density", "pg" => "page", "dl" => "delay", "cs" => "color_space");
     foreach ($simple_params as $param => $option) {
         $params[$param] = Cloudinary::option_consume($options, $option);
     }
     $params = array_filter($params);
     ksort($params);
     $join_pair_underscore = array("Cloudinary", "join_pair_underscore");
     $transformation = implode(",", array_map($join_pair_underscore, array_keys($params), array_values($params)));
     $raw_transformation = Cloudinary::option_consume($options, "raw_transformation");
     $transformation = implode(",", array_filter(array($transformation, $raw_transformation)));
     array_push($base_transformations, $transformation);
     return implode("/", array_filter($base_transformations));
 }
Example #4
0
 public static function generate_transformation_string(&$options = array())
 {
     $generate_base_transformation = "Cloudinary::generate_base_transformation";
     if (is_string($options)) {
         return $options;
     }
     if ($options == array_values($options)) {
         return implode("/", array_map($generate_base_transformation, $options));
     }
     $responsive_width = Cloudinary::option_consume($options, "responsive_width", Cloudinary::config_get("responsive_width"));
     $size = Cloudinary::option_consume($options, "size");
     if ($size) {
         list($options["width"], $options["height"]) = preg_split("/x/", $size);
     }
     $width = Cloudinary::option_get($options, "width");
     $height = Cloudinary::option_get($options, "height");
     $has_layer = Cloudinary::option_get($options, "underlay") || Cloudinary::option_get($options, "overlay");
     $angle = implode(Cloudinary::build_array(Cloudinary::option_consume($options, "angle")), ".");
     $crop = Cloudinary::option_consume($options, "crop");
     $no_html_sizes = $has_layer || !empty($angle) || $crop == "fit" || $crop == "limit" || $responsive_width;
     if (strlen($width) == 0 || $width && ($width == "auto" || floatval($width) < 1 || $no_html_sizes)) {
         unset($options["width"]);
     }
     if (strlen($height) == 0 || $height && (floatval($height) < 1 || $no_html_sizes)) {
         unset($options["height"]);
     }
     $background = Cloudinary::option_consume($options, "background");
     if ($background) {
         $background = preg_replace("/^#/", 'rgb:', $background);
     }
     $color = Cloudinary::option_consume($options, "color");
     if ($color) {
         $color = preg_replace("/^#/", 'rgb:', $color);
     }
     $base_transformations = Cloudinary::build_array(Cloudinary::option_consume($options, "transformation"));
     if (count(array_filter($base_transformations, "is_array")) > 0) {
         $base_transformations = array_map($generate_base_transformation, $base_transformations);
         $named_transformation = "";
     } else {
         $named_transformation = implode(".", $base_transformations);
         $base_transformations = array();
     }
     $effect = Cloudinary::option_consume($options, "effect");
     if (is_array($effect)) {
         $effect = implode(":", $effect);
     }
     $border = Cloudinary::option_consume($options, "border");
     if (is_array($border)) {
         $border_width = Cloudinary::option_get($border, "width", "2");
         $border_color = preg_replace("/^#/", 'rgb:', Cloudinary::option_get($border, "color", "black"));
         $border = $border_width . "px_solid_" . $border_color;
     }
     $flags = implode(Cloudinary::build_array(Cloudinary::option_consume($options, "flags")), ".");
     $dpr = Cloudinary::option_consume($options, "dpr", Cloudinary::config_get("dpr"));
     $duration = Cloudinary::norm_range_value(Cloudinary::option_consume($options, "duration"));
     $start_offset = Cloudinary::norm_range_value(Cloudinary::option_consume($options, "start_offset"));
     $end_offset = Cloudinary::norm_range_value(Cloudinary::option_consume($options, "end_offset"));
     $offset = Cloudinary::split_range(Cloudinary::option_consume($options, "offset"));
     if (!empty($offset)) {
         $start_offset = Cloudinary::norm_range_value($offset[0]);
         $end_offset = Cloudinary::norm_range_value($offset[1]);
     }
     $video_codec = Cloudinary::process_video_codec_param(Cloudinary::option_consume($options, "video_codec"));
     $params = array("a" => $angle, "b" => $background, "bo" => $border, "c" => $crop, "co" => $color, "dpr" => $dpr, "du" => $duration, "e" => $effect, "eo" => $end_offset, "fl" => $flags, "h" => $height, "so" => $start_offset, "t" => $named_transformation, "vc" => $video_codec, "w" => $width);
     $simple_params = array("ac" => "audio_codec", "af" => "audio_frequency", "ar" => "aspect_ratio", "br" => "bit_rate", "cs" => "color_space", "d" => "default_image", "dl" => "delay", "dn" => "density", "f" => "fetch_format", "g" => "gravity", "l" => "overlay", "o" => "opacity", "p" => "prefix", "pg" => "page", "q" => "quality", "r" => "radius", "u" => "underlay", "vs" => "video_sampling", "x" => "x", "y" => "y", "z" => "zoom");
     foreach ($simple_params as $param => $option) {
         $params[$param] = Cloudinary::option_consume($options, $option);
     }
     $param_filter = function ($value) {
         return $value === 0 || $value === '0' || trim($value) == true;
     };
     $params = array_filter($params, $param_filter);
     ksort($params);
     $join_pair = function ($key, $value) {
         return $key . "_" . $value;
     };
     $transformation = implode(",", array_map($join_pair, array_keys($params), array_values($params)));
     $raw_transformation = Cloudinary::option_consume($options, "raw_transformation");
     $transformation = implode(",", array_filter(array($transformation, $raw_transformation)));
     array_push($base_transformations, $transformation);
     if ($responsive_width) {
         $responsive_width_transformation = Cloudinary::config_get("responsive_width_transformation", Cloudinary::$DEFAULT_RESPONSIVE_WIDTH_TRANSFORMATION);
         array_push($base_transformations, Cloudinary::generate_transformation_string($responsive_width_transformation));
     }
     if ($width == "auto" || $responsive_width) {
         $options["responsive"] = true;
     }
     if ($dpr == "auto") {
         $options["hidpi"] = true;
     }
     return implode("/", array_filter($base_transformations));
 }
Example #5
0
 function update($public_id, $options = array())
 {
     $resource_type = \Cloudinary::option_get($options, "resource_type", "image");
     $type = \Cloudinary::option_get($options, "type", "upload");
     $uri = array("resources", $resource_type, $type, $public_id);
     $tags = \Cloudinary::option_get($options, "tags");
     $context = \Cloudinary::option_get($options, "context");
     $face_coordinates = \Cloudinary::option_get($options, "face_coordinates");
     $custom_coordinates = \Cloudinary::option_get($options, "custom_coordinates");
     $update_options = array_merge($this->only($options, array("moderation_status", "raw_convert", "ocr", "categorization", "detection", "similarity_search", "auto_tagging", "background_removal")), array("tags" => $tags ? implode(",", \Cloudinary::build_array($tags)) : $tags, "context" => $context ? \Cloudinary::encode_assoc_array($context) : $context, "face_coordinates" => $face_coordinates ? \Cloudinary::encode_double_array($face_coordinates) : $face_coordinates, "custom_coordinates" => $custom_coordinates ? \Cloudinary::encode_double_array($custom_coordinates) : $custom_coordinates));
     return $this->call_api("post", $uri, $update_options, $options);
 }