コード例 #1
0
ファイル: BaseUploader.class.php プロジェクト: Rming/novophp
 public function asidoResizeImg($args = array(), $crop = false)
 {
     asido::driver('gd');
     $source_image = $args["source_image"];
     $target_image = $args["target_image"];
     $width = $args["width"];
     $height = $args["height"];
     // process crop images
     $i1 = asido::image($source_image, $target_image);
     // fit and add white frame
     if ($crop) {
         $x = $args["x"];
         $y = $args["y"];
         Asido::crop($i1, $x, $y, $width, $height);
     } else {
         Asido::frame($i1, $width, $height, Asido::Color(255, 255, 255));
     }
     $i1->Save(ASIDO_OVERWRITE_ENABLED);
 }
コード例 #2
0
	function generateThumbnail($originalImgPath, $thumbDir, $prefix, $thumbWidth = 0, $thumbHeight = 0, $type = 'resize', $typeParams = array(), $filters = array())
	{
		$thumbSize = AriImageHelper::getThumbnailDimension($originalImgPath, $thumbWidth, $thumbHeight);
		if (!$thumbSize['w'] || !$thumbSize['h'] || !@is_readable($originalImgPath))
			return null;

		$width = $thumbSize['w'];
		$height = $thumbSize['h'];
		$path_parts = pathinfo($originalImgPath);

		$thumbName = AriImageHelper::generateThumbnailFileName($prefix, $originalImgPath, $width, $height, $type);
		$thumbImgPath = $thumbDir . DS . $thumbName;
		if (@file_exists($thumbImgPath) && @filemtime($thumbImgPath) > @filemtime($originalImgPath))
			return $thumbName;

		if (!AriImageHelper::initAsido())
			return ;
		$thumbImg = Asido::image($originalImgPath, $thumbImgPath);
		$needResize = true;		
		
		if ($type == 'crop')
		{
			Asido::crop(
				$thumbImg,
				intval(AriUtils::getParam($typeParams, 'x', 0), 10),
				intval(AriUtils::getParam($typeParams, 'y', 0), 10),
				$width ? $width : $height,
				$height ? $height : $width
			);
			$needResize = false;
		}
		else if ($type == 'cropresize')
		{
			Asido::crop(
				$thumbImg,
				intval(AriUtils::getParam($typeParams, 'x', 0), 10),
				intval(AriUtils::getParam($typeParams, 'y', 0), 10),
				intval(AriUtils::getParam($typeParams, 'width', 0), 10),
				intval(AriUtils::getParam($typeParams, 'height', 0), 10)
			);
		}

		if ($filters)
		{
			if (AriUtils::parseValueBySample(
					AriUtils::getParam($filters, 'grayscale', false),
					false)
				)
			{
				Asido::grayscale($thumbImg);
			}
			
			$rotateFilter = AriUtils::getParam($filters, 'rotate');
			if (is_array($rotateFilter) && 
				AriUtils::parseValueBySample(
					AriUtils::getParam($rotateFilter, 'enable', false),
					false)
				)
			{
				$angle = 0;
				$rotateType = AriUtils::getParam($rotateFilter, 'type', 'fixed');
				if ($rotateType == 'random')
				{
					$startAngle = intval(AriUtils::getParam($rotateFilter, 'startAngle', 0), 10);
					$endAngle = intval(AriUtils::getParam($rotateFilter, 'endAngle', 0), 10);
					$angle = rand($startAngle, $endAngle);
				}
				else
				{
					$angle = intval(AriUtils::getParam($rotateFilter, 'angle', 0), 10);
				}

				$angle = $angle % 360;
				if ($angle != 0)
				{
					Asido::rotate($thumbImg, $angle);
				}
			}
		}

		if ($needResize)
		{
			if (!$width)
				Asido::height($thumbImg, $height);
			else if (!$height)
				Asido::width($thumbImg, $width);
			else
				Asido::resize($thumbImg, $width, $height, ASIDO_RESIZE_STRETCH);
		}

		$thumbImg->save(ASIDO_OVERWRITE_ENABLED);
		
		return $thumbName;
	}
コード例 #3
0
                 $cropEndArray = explode(',', $cropEnd);
                 Asido::crop($img, $cropStartArray[0], $cropStartArray[1], $cropEndArray[0], $cropEndArray[1]);
             } else {
                 Asido::crop($img, $cropStartArray[0], $cropStartArray[1], $previewWidth, $previewHeight);
             }
         } else {
             Asido::crop($img, 0, 0, $previewWidth, $previewHeight);
         }
     } else {
         if ($imgWidth < $imgHeight) {
             $diff = ($imgHeight - $imgWidth) / 2;
             if ($cropStart) {
                 $cropStartArray = explode(',', $cropStart);
                 Asido::crop($img, $cropStartArray[0], $cropStartArray[1], $previewWidth, $previewHeight);
             } else {
                 Asido::crop($img, 0, 0, $previewWidth, $previewHeight);
             }
         }
     }
     Asido::resize($img, $previewWidth, $previewHeight, ASIDO_RESIZE_STRETCH);
 } else {
     if (strstr($convertImage, 'rotate')) {
         $rotateAttrs = explode(':', $convertImage);
         if (!$rotateAttrs[1]) {
             $rotateAttrs[1] = 90;
         }
         Asido::Rotate($img, $rotateAttrs[1]);
     } else {
         if (!$previewWidth) {
             Asido::height($img, $previewHeight);
         } else {
コード例 #4
0
ファイル: image.php プロジェクト: knigherrant/decopatio
 /**
  * Crops an image given the coordinates , width and height.
  *
  * @since	1.0
  * @access	public
  * @param	int		The coordinate position for x
  * @param	int		The coordinate position for y
  * @param	int		The width of the cropped image.
  * @param	int		The height of the cropped image.
  * @return	SocialImage		Returns itself for chaining.
  */
 public function crop($x = 0, $y = 0, $width, $height)
 {
     // Try to crop the current image resource.
     $this->adapter->crop($this->image, $x, $y, $width, $height);
     return $this;
 }
コード例 #5
0
 if (!@file_exists($thumbPath)) {
     $img = asido::image($imagePath, $thumbPath);
     if ($convertImage == 'crop' && $previewWidth && $previewHeight) {
         Asido::crop($img, 0, 0, $previewWidth, $previewHeight);
     } else {
         if ($convertImage == 'crop_resize' && $previewWidth && $previewHeight) {
             $imgSize = getimagesize($imagePath);
             $imgWidth = $imgSize[0];
             $imgHeight = $imgSize[1];
             if ($imgWidth > $imgHeight) {
                 $diff = ($imgWidth - $imgHeight) / 2;
                 Asido::crop($img, $diff, 0, $imgWidth - 2 * $diff, $imgHeight);
             } else {
                 if ($imgWidth < $imgHeight) {
                     $diff = ($imgHeight - $imgWidth) / 2;
                     Asido::crop($img, 0, $diff, $imgWidth, $imgHeight - 2 * $diff);
                 }
             }
             Asido::resize($img, $previewWidth, $previewHeight, ASIDO_RESIZE_STRETCH);
         } else {
             if (strstr($convertImage, 'rotate')) {
                 $rotateAttrs = explode(':', $convertImage);
                 if (!$rotateAttrs[1]) {
                     $rotateAttrs[1] = 90;
                 }
                 Asido::Rotate($img, $rotateAttrs[1]);
             } else {
                 if (!$previewWidth) {
                     Asido::height($img, $previewHeight);
                 } else {
                     if (!$previewHeight) {