Cloudinary::text_style PHP 메소드

text_style() 개인적인 정적인 메소드

private static text_style ( $layer, $layer_parameter )
    private static function text_style($layer, $layer_parameter)
    {
        $font_family = Cloudinary::option_get($layer, "font_family");
        $font_size = Cloudinary::option_get($layer, "font_size");
        $keywords = array();
        foreach (Cloudinary::$LAYER_KEYWORD_PARAMS as $attr => $default_value) {
            $attr_value = Cloudinary::option_get($layer, $attr, $default_value);
            if ($attr_value != $default_value) {
                array_push($keywords, $attr_value);
            }
        }
        $letter_spacing = Cloudinary::option_get($layer, "letter_spacing");
        if ($letter_spacing != NULL) {
            array_push($keywords, "letter_spacing_{$letter_spacing}");
        }
        $line_spacing = Cloudinary::option_get($layer, "line_spacing");
        if ($line_spacing != NULL) {
            array_push($keywords, "line_spacing_{$line_spacing}");
        }
        $has_text_options = $font_size != NULL || $font_family != NULL || !empty($keywords);
        if (!$has_text_options) {
            return NULL;
        }
        if ($font_family == NULL) {
            throw new InvalidArgumentException("Must supply font_family for text in {$layer_parameter}");
        }
        if ($font_size == NULL) {
            throw new InvalidArgumentException("Must supply font_size for text in {$layer_parameter}");
        }
        array_unshift($keywords, $font_size);
        array_unshift($keywords, $font_family);
        return implode("_", array_filter($keywords, 'Cloudinary::is_not_null'));
    }

Usage Example

예제 #1
0
 private static function process_layer($layer, $layer_parameter)
 {
     if (is_array($layer)) {
         $resource_type = Cloudinary::option_get($layer, "resource_type");
         $type = Cloudinary::option_get($layer, "type");
         $text = Cloudinary::option_get($layer, "text");
         $text_style = NULL;
         $public_id = Cloudinary::option_get($layer, "public_id");
         $format = Cloudinary::option_get($layer, "format");
         $components = array();
         if ($public_id != NULL) {
             $public_id = str_replace("/", ":", $public_id);
             if ($format != NULL) {
                 $public_id = $public_id . "." . $format;
             }
         }
         if ($text == NULL && $resource_type != "text") {
             if ($public_id == NULL) {
                 throw new InvalidArgumentException("Must supply public_id for {$resource_type} {$layer_parameter}");
             }
             if ($resource_type == "subtitles") {
                 $text_style = Cloudinary::text_style($layer, $layer_parameter);
             }
         } else {
             $resource_type = "text";
             $type = NULL;
             // type is ignored for text layers
             $text_style = Cloudinary::text_style($layer, $layer_parameter);
             #FIXME duplicate
             if ($text != NULL) {
                 if (!($public_id != NULL xor $text_style != NULL)) {
                     throw new InvalidArgumentException("Must supply either style parameters or a public_id when providing text parameter in a text {$layer_parameter}");
                 }
                 $text = Cloudinary::smart_escape($text);
                 $text = str_replace("%2C", "%252C", $text);
                 $text = str_replace("/", "%252F", $text);
             }
         }
         if ($resource_type != "image") {
             array_push($components, $resource_type);
         }
         if ($type != "upload") {
             array_push($components, $type);
         }
         array_push($components, $text_style);
         array_push($components, $public_id);
         array_push($components, $text);
         $layer = implode(":", array_filter($components, 'Cloudinary::is_not_null'));
     }
     return $layer;
 }