本文整理汇总了PHP中imagick::clone方法的典型用法代码示例。如果您正苦于以下问题:PHP imagick::clone方法的具体用法?PHP imagick::clone怎么用?PHP imagick::clone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imagick
的用法示例。
在下文中一共展示了imagick::clone方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mkdir
mkdir($mediadir, 0777, true);
}
$filename = $query_string['id'] . '.' . $query_string['hash'] . '.' . $query_string['ext'];
$writeTo = $mediadir . $filename;
if (!$width || !$height) {
header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found', true, 404);
exit;
}
if (!($size = getimagesize($fullPath))) {
header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found', true, 404);
exit;
}
list($currentWidth, $currentHeight, $currentType) = $size;
if (class_exists('imagick')) {
$new_image_obj = new imagick($fullPath);
$new_image = $new_image_obj->clone();
$new_image->setImageColorspace(Imagick::COLORSPACE_RGB);
$new_image->flattenImages();
if ($is_beyond_original && ($width > $currentWidth || $height > $currentHeight)) {
$width = $currentWidth;
$height = $currentHeight;
}
if (!$aspect) {
$new_image->cropThumbnailImage($width, $height);
} else {
$new_image->scaleImage($width, $height, false);
}
$new_image->writeImage($writeTo);
} else {
$target['width'] = $currentWidth;
$target['height'] = $currentHeight;
示例2: date
// узнаем размеры водяного знака
$watermark_width = $watermark->getImageWidth();
$watermark_height = $watermark->getImageHeight();
// посчитать x и y
$left = $im_width - $watermark_width - 10;
$top = $im_height - $watermark_height - 10;
// накладываем watermark на оригинальное изображение
$im->compositeImage($watermark, imagick::COMPOSITE_OVER, $left, $top);
// сохраняем оригинал
$im->writeImage('./images/' . $image_name . '.' . $p[1]);
} else {
// сохраняем .gif с учетом анимации
$im->writeImages('./images/' . $image_name . '.' . $p[1], true);
}
// Копируем объект для различных типов
$large = $im->clone();
$square = $im->clone();
// Создаем квадратное изображение 160x160 px
$square->cropThumbnailImage(160, 160);
$square->writeImage('./images/' . $image_name . 's' . '.' . $p[1]);
// Создаем большое изображение с шириной 640 px и переменной высотой
$large->thumbnailImage(640, 0);
$large->writeImage('./images/' . $image_name . 'l' . '.' . $p[1]);
// добавляем имя, расширение, дату загрузки изображения в БД
// выбираем коллекцию
$collection = $db->images;
// добавляем новый документ - изображение в коллекцию Images
$collection->insert(array('image' => $image_name, 'ext' => $p[1], 'title' => '', 'views' => 0, 'gallery' => 0, 'date' => date("d-m-Y H:i:s")));
//$image_names[] = $image_name;
$_SESSION['image_name'] = $image_name;
echo $image_name;
示例3: resizeFile
function resizeFile($fullPath, $width = 600, $height = 400, $writeTo, $aspect = true, $is_beyond_original = false, $query_string = array())
{
if (!$width || !$height) {
return false;
}
if (!($size = getimagesize($fullPath))) {
return false;
}
list($currentWidth, $currentHeight, $currentType) = $size;
$return = false;
if (class_exists('imagick')) {
$new_image_obj = new imagick($fullPath);
$new_image = $new_image_obj->clone();
$new_image->setImageColorspace(Imagick::COLORSPACE_RGB);
$new_image->flattenImages();
if ($is_beyond_original && ($width > $currentWidth || $height > $currentHeight)) {
$width = $currentWidth;
$height = $currentHeight;
}
if (!$aspect) {
$new_image->cropThumbnailImage($width, $height);
} else {
$new_image->scaleImage($width, $height, false);
}
if ($new_image->writeImage($writeTo)) {
$return = true;
}
} else {
$target['width'] = $currentWidth;
$target['height'] = $currentHeight;
$target['x'] = $target['y'] = 0;
$types = array(1 => 'gif', 'jpeg', 'png', 'swf', 'psd', 'wbmp');
_setMemoryLimitForImage($fullPath);
$image = call_user_func('imagecreatefrom' . $types[$currentType], $fullPath);
ini_restore('memory_limit');
if ($aspect) {
if ($currentHeight / $height > $currentWidth / $width) {
$width = ceil($currentWidth / $currentHeight * $height);
} else {
$height = ceil($width / ($currentWidth / $currentHeight));
}
} else {
$proportion_X = $currentWidth / $width;
$proportion_Y = $currentHeight / $height;
if ($proportion_X > $proportion_Y) {
$proportion = $proportion_Y;
} else {
$proportion = $proportion_X;
}
$target['width'] = $width * $proportion;
$target['height'] = $height * $proportion;
$original['diagonal_center'] = round(sqrt($currentWidth * $currentWidth + $currentHeight * $currentHeight) / 2);
$target['diagonal_center'] = round(sqrt($target['width'] * $target['width'] + $target['height'] * $target['height']) / 2);
$crop = round($original['diagonal_center'] - $target['diagonal_center']);
if ($proportion_X < $proportion_Y) {
$target['x'] = 0;
$target['y'] = round($currentHeight / 2 * $crop / $target['diagonal_center']);
} else {
$target['x'] = round($currentWidth / 2 * $crop / $target['diagonal_center']);
$target['y'] = 0;
}
}
if ($is_beyond_original && ($width > $currentWidth || $height > $currentHeight)) {
$width = $currentWidth;
$height = $currentHeight;
}
if (function_exists('imagecreatetruecolor') && ($temp = imagecreatetruecolor($width, $height))) {
imagecopyresampled($temp, $image, 0, 0, $target['x'], $target['y'], $width, $height, $target['width'], $target['height']);
} else {
$temp = imagecreate($width, $height);
imagecopyresized($temp, $image, 0, 0, 0, 0, $width, $height, $currentWidth, $currentHeight);
}
if (strtolower($query_string['ext']) == 'png') {
imagepng($temp, $writeTo);
} else {
if (strtolower($query_string['ext']) == 'jpg' || strtolower($query_string['ext']) == 'jpeg') {
imagejpeg($temp, $writeTo, 100);
} else {
if (strtolower($query_string['ext']) == 'gif') {
imagegif($temp, $writeTo);
}
}
}
ob_start();
call_user_func('image' . $types[$currentType], $temp);
$return = ob_get_clean();
imagedestroy($image);
imagedestroy($temp);
}
return $return;
}