本文整理汇总了PHP中TimberHelper::get_rel_path方法的典型用法代码示例。如果您正苦于以下问题:PHP TimberHelper::get_rel_path方法的具体用法?PHP TimberHelper::get_rel_path怎么用?PHP TimberHelper::get_rel_path使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TimberHelper
的用法示例。
在下文中一共展示了TimberHelper::get_rel_path方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wp_resize_letterbox
function wp_resize_letterbox($src, $w, $h, $color = '#000000')
{
//$old_file = TimberHelper::get_full_path($src);
$urlinfo = parse_url($src);
$old_file = ABSPATH . $urlinfo['path'];
$new_file = TimberImageHelper::get_letterbox_file_path($urlinfo['path'], $w, $h);
$new_file_rel = TimberImageHelper::get_letterbox_file_rel($urlinfo['path'], $w, $h);
$new_file_boxed = str_replace('-lb-', '-lbox-', $new_file);
if (file_exists($new_file_boxed)) {
$new_file_rel = str_replace('-lb-', '-lbox-', $new_file_rel);
return $new_file_rel;
}
$bg = imagecreatetruecolor($w, $h);
$c = hexrgb($color);
$white = imagecolorallocate($bg, $c['red'], $c['green'], $c['blue']);
imagefill($bg, 0, 0, $white);
$image = wp_get_image_editor($old_file);
if (!is_wp_error($image)) {
$current_size = $image->get_size();
$ow = $current_size['width'];
$oh = $current_size['height'];
$new_aspect = $w / $h;
$old_aspect = $ow / $oh;
if ($new_aspect > $old_aspect) {
//taller than goal
$h_scale = $h / $oh;
$owt = $ow * $h_scale;
$y = 0;
$x = $w / 2 - $owt / 2;
$oht = $h;
$image->crop(0, 0, $ow, $oh, $owt, $oht);
} else {
$w_scale = $w / $ow;
$oht = $oh * $w_scale;
$x = 0;
$y = $h / 2 - $oht / 2;
$owt = $w;
$image->crop(0, 0, $ow, $oh, $owt, $oht);
}
$image->save($new_file);
$func = 'imagecreatefromjpeg';
$ext = pathinfo($new_file, PATHINFO_EXTENSION);
if ($ext == 'gif') {
$func = 'imagecreatefromgif';
} else {
if ($ext == 'png') {
$func = 'imagecreatefrompng';
}
}
$image = $func($new_file);
imagecopy($bg, $image, $x, $y, 0, 0, $owt, $oht);
$new_file = str_replace('-lb-', '-lbox-', $new_file);
imagejpeg($bg, $new_file);
return TimberHelper::get_rel_path($new_file);
} else {
TimberHelper::error_log($image);
}
return null;
}