set( $value ); } /** * Set property value. * * @param mixed $value Value to set. */ public function set( $value ) { $this->resize_type = isset( $value['type'] ) ? $value['type'] : ''; $this->enlarge = isset( $value['enlarge'] ) ? $value['enlarge'] : self::$default_enlarge; $this->gravity = isset( $value['gravity'] ) ? is_array( $value['gravity'] ) ? self::GRAVITY_FOCUS_POINT : $value['gravity'] : ''; if ( $this->gravity === self::GRAVITY_FOCUS_POINT ) { $this->focus_point_x = $value['gravity'][0]; $this->focus_point_y = $value['gravity'][1]; } } /** * Return property value. * * @return mixed */ public function get() { if ( empty( $this->resize_type ) ) { return []; } if ( empty( $this->gravity ) ) { return [ 'type' => $this->resize_type ]; } if ( $this->gravity === self::GRAVITY_FOCUS_POINT ) { return [ 'type' => $this->gravity, 'gravity' => [ $this->focus_point_x, $this->focus_point_y ] ]; } return [ 'type' => $this->resize_type, 'gravity' => $this->gravity, 'enlarge' => $this->enlarge, ]; } /** * Return ImageProxy URL formatted string property. * * @return string */ public function toString() { $resize = sprintf( 'rt:%s', $this->resize_type ); $resize .= sprintf( '/g:%s', $this->gravity ); if ( $this->gravity === self::GRAVITY_FOCUS_POINT ) { $resize .= sprintf( ':%s:%s', $this->focus_point_x, $this->focus_point_y ); } if ( $this->enlarge ) { $resize .= '/el:1'; } return $resize; } }