當前位置: 首頁>>代碼示例>>PHP>>正文


PHP TimberHelper::preslashit方法代碼示例

本文整理匯總了PHP中TimberHelper::preslashit方法的典型用法代碼示例。如果您正苦於以下問題:PHP TimberHelper::preslashit方法的具體用法?PHP TimberHelper::preslashit怎麽用?PHP TimberHelper::preslashit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在TimberHelper的用法示例。


在下文中一共展示了TimberHelper::preslashit方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: resize

 public static function resize($src, $w, $h = 0)
 {
     if (empty($src)) {
         return '';
     }
     if (strstr($src, 'http') && !strstr($src, home_url())) {
         $src = self::sideload_image($src);
     }
     $abs = false;
     if (strstr($src, 'http')) {
         $abs = true;
     }
     //oh good, it's a relative image in the uploads folder!
     $path_parts = pathinfo($src);
     $basename = $path_parts['filename'];
     $ext = $path_parts['extension'];
     $dir = $path_parts['dirname'];
     $newbase = $basename . '-r-' . $w . 'x' . $h;
     $new_path = $dir . '/' . $newbase . '.' . $ext;
     $new_path = str_replace(site_url(), '', $new_path);
     $new_root_path = ABSPATH . $new_path;
     $old_root_path = ABSPATH . str_replace(site_url(), '', $src);
     $old_root_path = str_replace('//', '/', $old_root_path);
     $new_root_path = str_replace('//', '/', $new_root_path);
     if (file_exists($new_root_path)) {
         if ($abs) {
             return untrailingslashit(site_url()) . $new_path;
         } else {
             return TimberHelper::preslashit($new_path);
         }
         return $new_path;
     }
     $image = wp_get_image_editor($old_root_path);
     if (!is_wp_error($image)) {
         $current_size = $image->get_size();
         $ow = $current_size['width'];
         $oh = $current_size['height'];
         $old_aspect = $ow / $oh;
         if ($h) {
             $new_aspect = $w / $h;
             if ($new_aspect > $old_aspect) {
                 //cropping a vertical photo horitzonally
                 $oht = $ow / $new_aspect;
                 $oy = ($oh - $oht) / 6;
                 $image->crop(0, $oy, $ow, $oht, $w, $h);
             } else {
                 $owt = $oh * $new_aspect;
                 $ox = $ow / 2 - $owt / 2;
                 $image->crop($ox, 0, $owt, $oh, $w, $h);
             }
         } else {
             $h = $w;
             if ($old_aspect < 1) {
                 $h = $w / $old_aspect;
                 $image->crop(0, 0, $ow, $oh, $w, $h);
             } else {
                 $image->resize($w, $h);
             }
         }
         $result = $image->save($new_root_path);
         if (is_wp_error($result)) {
             error_log('Error resizing image');
             error_log(print_r($result, true));
         }
         if ($abs) {
             return untrailingslashit(site_url()) . $new_path;
         }
         return $new_path;
     } else {
         if (isset($image->error_data['error_loading_image'])) {
             TimberHelper::error_log('Error loading ' . $image->error_data['error_loading_image']);
         } else {
             TimberHelper::error_log($image);
         }
     }
     return $src;
 }
開發者ID:pedrokoblitz,項目名稱:centro-dialogo-aberto,代碼行數:77,代碼來源:timber-image-helper.php


注:本文中的TimberHelper::preslashit方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。