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::process_border(Cloudinary::option_consume($options, "border")); $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")); $overlay = Cloudinary::process_layer(Cloudinary::option_consume($options, "overlay"), "overlay"); $underlay = Cloudinary::process_layer(Cloudinary::option_consume($options, "underlay"), "underlay"); $if = Cloudinary::process_if(Cloudinary::option_consume($options, "if")); $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, "l" => $overlay, "so" => $start_offset, "t" => $named_transformation, "u" => $underlay, "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", "o" => "opacity", "p" => "prefix", "pg" => "page", "q" => "quality", "r" => "radius", "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); if (isset($if)) { $params = array_merge(array("if" => $if), $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)); }