本文整理汇总了PHP中Thumbnail::dump方法的典型用法代码示例。如果您正苦于以下问题:PHP Thumbnail::dump方法的具体用法?PHP Thumbnail::dump怎么用?PHP Thumbnail::dump使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Thumbnail
的用法示例。
在下文中一共展示了Thumbnail::dump方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: imageGenerator
/**
* Image generator.
*
* @param string $imageFile Image name.
* @param int $maxSize Max size.
* @param string $newFileName New generated file name.
* @param int $qualitat Quality.
* @param string $waterMark Watermark.
*
* @return array Image resolution.
*/
public static function imageGenerator($imageFile, $maxSize, $newFileName, $qualitat, $waterMark = '')
{
if (!file_exists($imageFile)) {
return false;
}
// Size setter.
list($width, $height, $type) = getimagesize($imageFile);
$larger = $width > $height ? $width : $height;
$smaller = $width > $height ? $height : $width;
if ($larger <= $maxSize) {
$newLarger = $larger;
$newSmaller = $smaller;
} else {
$multiplication = $maxSize / $larger;
$newLarger = $maxSize;
$newSmaller = $smaller * $multiplication;
}
$newWidth = $width > $height ? $newLarger : $newSmaller;
$newHeight = $width > $height ? $newSmaller : $newLarger;
switch ($type) {
case 1:
$kep = imagecreatefromgif($imageFile);
break;
case 2:
$kep = imagecreatefromjpeg($imageFile);
break;
case 3:
$kep = imagecreatefrompng($imageFile);
break;
}
$ujkep = imagecreatetruecolor($newWidth, $newHeight);
imagecopyresampled($ujkep, $kep, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
imagejpeg($ujkep, $newFileName, $qualitat);
// Contructor and set source image file
$thumb = new Thumbnail($newFileName);
// [OPTIONAL] set maximun memory usage, default 32 MB ('32M'). (use '16M' or '32M' for litter images)
$thumb->memory_limit = '64M';
// [OPTIONAL] set maximun execution time, default 30 seconds ('30'). (use '60' for big images o slow server)
$thumb->max_execution_time = 60;
if ($waterMark != '') {
// [OPTIONAL] set watermark source file, only PNG format [RECOMENDED ONLY WITH GD 2]
$thumb->img_watermark = 'static/images/watermak/' . $waterMark;
}
// [OPTIONAL] set watermark vertical position, TOP | CENTER | BOTTOM
$thumb->img_watermark_Valing = 'CENTER';
// [OPTIONAL] set watermark horizonatal position, LEFT | CENTER | RIGHT
$thumb->img_watermark_Haling = 'CENTER';
$thumb->process();
$newImage = $thumb->dump();
imagejpeg($newImage, $newFileName, $qualitat);
return array($newWidth, $newHeight);
}