コード例 #1
0
ファイル: Jumbotron.php プロジェクト: o2system/o2bootstrap
 public function set_image($image)
 {
     if (is_file($image)) {
         $image = path_to_url($image);
     }
     $style = array("background-image: url('{$image}')", 'background-position: center', 'background-size: cover');
     $this->add_attribute('style', implode(';', $style));
     return $this;
 }
コード例 #2
0
ファイル: Utils.php プロジェクト: boudra/yapf
 function guess_app_url()
 {
     $base_dir = str_replace("\\", '/', dirname($_SERVER['SCRIPT_NAME']));
     $script_relative = str_replace("\\", '/', $_SERVER['SCRIPT_NAME']);
     $script_absolute = str_replace("\\", '/', $_SERVER['SCRIPT_FILENAME']);
     $doc_root = preg_replace("!{$script_relative}\$!", '', $script_absolute);
     $base_url = preg_replace("!^{$doc_root}!", '', $base_dir);
     return path_to_url($base_url);
 }
コード例 #3
0
ファイル: Image.php プロジェクト: o2system/o2bootstrap
 public function set_source($source)
 {
     if (is_file($source)) {
         $this->_realpath = $source;
         $source = path_to_url($source);
         $this->_attributes['src'] = $source;
     } elseif (strpos($source, 'http') !== FALSE) {
         $this->_attributes['src'] = $source;
     }
     return $this;
 }
コード例 #4
0
function gen_image_src($attachment_id, $width = false, $height = false, $crop = false)
{
    // If user provide attachment url instead of attachment id
    if (filter_var($attachment_id, FILTER_VALIDATE_URL)) {
        $attachment_id = get_attachment_id_from_src($attachment_id);
    }
    // get the file path
    $file = get_attached_file($attachment_id);
    // validate attachment exist
    if ($file == '') {
        return '';
    }
    // calculate and set width/height if one of width or height is false.
    if ($width == false xor $height == false) {
        $img = wp_get_attachment_image_src($attachment_id, 'full');
        if ($img != false) {
            $img_ratio = $img[1] / $img[2];
            if ($width == false) {
                $width = $height * $img_ratio;
            } else {
                if ($height == false) {
                    $height = $width / $img_ratio;
                }
            }
        }
    }
    // build the resized filename
    $resize_extend = $width != false ? '-' . floor($width) : '';
    $resize_extend .= $height != false ? 'x' . floor($height) : '';
    $resize_extend .= $resize_extend != '' && $crop != false ? '-cropped' : '';
    $resized_file = $cachefile = substr_replace($file, $resize_extend, strrpos($file, '.'), 0);
    // check the resized file existance
    $cache_exist = file_exists($resized_file);
    if (!$cache_exist) {
        $editor = wp_get_image_editor($file);
        $editor->resize($width, $height, $crop);
        $new_image_info = $editor->save($resized_file);
        $url = path_to_url($new_image_info['path']);
    } else {
        $url = path_to_url($resized_file);
    }
    return $url;
}