本文整理汇总了PHP中Thumbnail::scale方法的典型用法代码示例。如果您正苦于以下问题:PHP Thumbnail::scale方法的具体用法?PHP Thumbnail::scale怎么用?PHP Thumbnail::scale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Thumbnail
的用法示例。
在下文中一共展示了Thumbnail::scale方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_thumbnail_file
function get_thumbnail_file($asset, $blog, $args)
{
# Parse args
$format = '%f-thumb-%wx%h-%i%x';
if (isset($args['format'])) {
$format = $args['format'];
}
# Get parameter
$site_path = $blog->site_path();
$site_path = preg_replace('/\\/$/', '', $site_path);
$filename = asset_path($asset->asset_file_path, $blog);
# Retrieve thumbnail
$mt = MT::get_instance();
$path_parts = pathinfo($filename);
$cache_path = $mt->config('AssetCacheDir');
$ts = preg_replace('![^0-9]!', '', $asset->asset_created_on);
$date_stamp = format_ts('%Y/%m', $ts, $blog);
$base_path = $site_path;
$archive_path = $blog->archive_path();
if (preg_match('/^%a/', $asset->asset_file_path) && !empty($archive_path)) {
$base_path = $blog->archive_path();
$base_path = preg_replace('/\\/$/', '', $base_path);
}
$cache_dir = $base_path . DIRECTORY_SEPARATOR . $cache_path . DIRECTORY_SEPARATOR . $date_stamp . DIRECTORY_SEPARATOR;
$thumb_name = $cache_dir . $format;
# generate thumbnail
require_once 'thumbnail_lib.php';
$thumb = new Thumbnail($filename);
$thumb->id($asset->id);
$thumb->format($thumb_name);
$thumb->type('auto');
if (isset($args['width'])) {
$thumb->width($args['width']);
}
if (isset($args['height'])) {
$thumb->height($args['height']);
}
if (isset($args['scale'])) {
$thumb->scale($args['scale']);
}
if (isset($args['square'])) {
$thumb->square($args['square'] ? true : false);
}
if (!$thumb->get_thumbnail()) {
return '';
}
# make url
$basename = basename($thumb->dest());
$base_url = $blog->site_url();
$archive_url = $blog->archive_url();
if (preg_match('/^%a/', $asset->asset_file_path) && !empty($archive_url)) {
$base_url = $blog->archive_url();
}
if (!preg_match('!/$!', $base_url)) {
$base_url .= '/';
}
if (DIRECTORY_SEPARATOR != '/') {
$cache_path = str_replace(DIRECTORY_SEPARATOR, '/', $cache_path);
}
$thumb_url = $base_url . $cache_path . '/' . $date_stamp . '/' . $basename;
return array($thumb_url, $thumb->width(), $thumb->height(), $thumb->dest());
}