Ejemplo n.º 1
0
 function rotate($angle)
 {
     $this->_load_data();
     if ($this->data) {
         imagick_rotate($this->data, -$angle);
         return true;
     } else {
         return false;
     }
 }
 /**
  * Rotate the image clockwise
  *
  * @param Asido_TMP &$tmp
  * @param float $angle
  * @param Asido_Color &$color
  * @return boolean
  * @access protected
  */
 function __rotate(&$tmp, $angle, &$color)
 {
     // skip full loops
     //
     if ($angle % 360 == 0) {
         return true;
     }
     $a = $tmp->image_height;
     $b = $tmp->image_width;
     // do the virtual `border`
     //
     $c = $a * cos(deg2rad($angle)) * sin(deg2rad($angle));
     $d = $b * cos(deg2rad($angle)) * sin(deg2rad($angle));
     // do the rest of the math
     //
     $a2 = $b * sin(deg2rad($angle)) + $a * cos(deg2rad($angle));
     $b2 = $a * sin(deg2rad($angle)) + $b * cos(deg2rad($angle));
     $a3 = 2 * $d + $a;
     $b3 = 2 * $c + $b;
     $a4 = $b3 * sin(deg2rad($angle)) + $a3 * cos(deg2rad($angle));
     $b4 = $a3 * sin(deg2rad($angle)) + $b3 * cos(deg2rad($angle));
     // create the `border` canvas
     //
     $t = $this->__canvas($b + 2 * $c, $a + 2 * $d, $color);
     // copy the image
     //
     imagick_composite($t->target, IMAGICK_COMPOSITE_OP_OVER, $tmp->target, $c, $d);
     // rotate the whole thing
     //
     imagick_rotate($t->target, $angle);
     // `final` result
     //
     $f = $this->__canvas($b2, $a2, $color);
     imagick_composite($f->target, IMAGICK_COMPOSITE_OP_OVER, $t->target, -(floor($b4) - $b2) / 2, -(floor($a4) - $a2) / 2);
     $this->__destroy_target($t);
     $this->__destroy_target($tmp);
     $tmp->target = $f->target;
     $tmp->image_width = $b2;
     $tmp->image_height = $a2;
     return true;
 }
Ejemplo n.º 3
0
 /**
  * Rotates the current image
  * Note: color mask are currently not supported
  *
  * @param   int     Rotation angle in degree
  * @param   array   No options are currently supported
  *
  * @return bool|PEAR_Error TRUE or a PEAR_Error object on error
  * @access public
  */
 function rotate($angle, $options = null)
 {
     if ($angle % 360 == 0) {
         return true;
     }
     if (!imagick_rotate($this->imageHandle, $angle)) {
         return $this->raiseError('Cannot create a new imagick image for the rotation.', IMAGE_TRANSFORM_ERROR_FAILED);
     }
     $this->new_x = imagick_getwidth($this->imageHandle);
     $this->new_y = imagick_getheight($this->imageHandle);
     return true;
 }
Ejemplo n.º 4
0
 /**
  * @param $angle
  */
 function rotateimage($angle)
 {
     if ($this->uselib == "imagick") {
         //Imagick and GD have different opinion what is 90 degree. right or left?
         imagick_rotate($this->imagehandle, -$angle);
     } else {
         if ($this->uselib == "gd") {
             if ($this->gdversion > 2.0) {
                 //I know, it's PHP <= 4.3.0. It destroys images if u try to rotate them
                 $this->imagehandle = imagerotate($this->imagehandle, $angle, 0);
             }
         }
     }
     // update the $this->image
     $this->writeimagetostring();
     //get new sizex, sizey
     $this->oldxsize = $this->xsize;
     $this->oldysize = $this->ysize;
     $this->getimageinfo();
 }
 /**
  * Rotate the image clockwise: only rectangular rotates are supported (90,180,270)
  *
  * @param Asido_TMP &$tmp
  * @param float $angle
  * @param Asido_Color &$color
  * @return boolean
  * @access protected
  */
 function __rotate(&$tmp, $angle, &$color)
 {
     // skip full loops
     //
     if ($angle % 360 == 0) {
         return true;
     }
     // rectangular rotates are OK
     //
     if ($angle % 90 == 0) {
         if (imagick_rotate($tmp->target, $angle)) {
             $tmp->image_width = imagick_getWidth($tmp->target);
             $tmp->image_height = imagick_getHeight($tmp->target);
             return true;
         }
     }
     return false;
 }
function image_rotation($im, $angle, $crop = false)
{
    $fonction = array('image_rotation', func_get_args());
    $image = _image_valeurs_trans($im, "rot-{$angle}-{$crop}", "png", $fonction);
    if (!$image) {
        return "";
    }
    $im = $image["fichier"];
    $dest = $image["fichier_dest"];
    $creer = $image["creer"];
    if ($creer) {
        $effectuer_gd = true;
        if (method_exists('Imagick', 'rotateImage')) {
            $imagick = new Imagick();
            $imagick->readImage($im);
            $imagick->rotateImage(new ImagickPixel('none'), $angle);
            $imagick->writeImage($dest);
            $effectuer_gd = false;
        } else {
            if ($GLOBALS['meta']['image_process'] == "convert") {
                if (_CONVERT_COMMAND != '') {
                    @define('_CONVERT_COMMAND', 'convert');
                    @define('_ROTATE_COMMAND', _CONVERT_COMMAND . ' -background none -rotate %t %src %dest');
                } else {
                    @define('_ROTATE_COMMAND', '');
                }
                if (_ROTATE_COMMAND !== '') {
                    $commande = str_replace(array('%t', '%src', '%dest'), array($angle, escapeshellcmd($im), escapeshellcmd($dest)), _ROTATE_COMMAND);
                    spip_log($commande);
                    exec($commande);
                    if (file_exists($dest)) {
                        $effectuer_gd = false;
                    }
                }
            } elseif (function_exists('imagick_rotate')) {
                $handle = imagick_readimage($im);
                if ($handle && imagick_isopaqueimage($handle)) {
                    imagick_setfillcolor($handle, 'transparent');
                    imagick_rotate($handle, $angle);
                    imagick_writeimage($handle, $dest);
                    $effectuer_gd = false;
                }
            }
        }
        if ($effectuer_gd) {
            // Creation de l'image en deux temps
            // de facon a conserver les GIF transparents
            $im = $image["fonction_imagecreatefrom"]($im);
            imagepalettetotruecolor($im);
            $im = image_RotateBicubic($im, $angle, true);
            _image_gd_output($im, $image);
            imagedestroy($im);
        }
    }
    list($src_y, $src_x) = taille_image($dest);
    return _image_ecrire_tag($image, array('src' => $dest, 'width' => $src_x, 'height' => $src_y));
}
Ejemplo n.º 7
0
 public function landscape()
 {
     if (!HAS_IMAGICK) {
         throw new Exception('Landscape graphs need IMagick installed');
     }
     $filename = $this->makeFileName(true);
     $source = imagick_readimage($filename);
     $rotate = imagick_rotate($source, 270);
     imagick_writeimage($source, $filename);
 }
Ejemplo n.º 8
0
 function rotate($angle)
 {
     imagick_rotate(&$this->data, -$angle);
     return true;
 }
Ejemplo n.º 9
0
            break;
    }
    if ($count == 3) {
        $files = MooAutoLoad("MooFiles");
        $files->fileDelete('../' . $file[0] . '.' . $file[1] % 4 . '.' . $file[2]);
        echo $file[1];
    } else {
        echo 0;
    }
}
/***************************************控制层(V)***********************************/
header("Cache-Control: no-cache, must-revalidate");
// HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// 过去的时间
//判断是否登录
adminUserInfo();
if (empty($GLOBALS['adminid'])) {
    echo 'nologin';
    exit;
}
$n = MooGetGPC('n', 'string');
switch ($n) {
    //note 检查会员ID
    case 'resize_and_crop':
        resize_and_crop();
        break;
    case 'imagick_rotate':
        imagick_rotate();
        break;
}
Ejemplo n.º 10
0
function action_tourner_post($r)
{
	$arg = $r[1];
	$row = sql_fetsel("fichier", "spip_documents", "id_document=$arg");

	if (!$row) return;

	include_spip('inc/charsets');	# pour le nom de fichier
	include_spip('inc/documents');
	// Fichier destination : on essaie toujours de repartir de l'original
	$var_rot = $r[2];
	include_spip('inc/distant'); # pour copie_locale
	$src = _DIR_RACINE . copie_locale(get_spip_doc($row['fichier']));
	if (preg_match(',^(.*)-r(90|180|270)\.([^.]+)$,', $src, $match)) {
		$effacer = $src;
		$src = $match[1].'.'.$match[3];
		$var_rot += intval($match[2]);
	}
	$var_rot = ((360 + $var_rot) % 360); // 0, 90, 180 ou 270

	if ($var_rot > 0) {
		$dest = preg_replace(',\.[^.]+$,', '-r'.$var_rot.'$0', $src);
		spip_log("rotation $var_rot $src : $dest");

		$process = $GLOBALS['meta']['image_process'];

		// imagick (php4-imagemagick)
		if ($process == 'imagick') {
			$handle = imagick_readimage($src);
			imagick_rotate($handle, $var_rot);
			imagick_write($handle, $dest);
			if (!@file_exists($dest)) return;	// echec imagick
		}
		else if ($process == "gd2") { // theoriquement compatible gd1, mais trop forte degradation d'image
			gdRotate ($src, $dest, $var_rot);
		}
		else if ($process == "convert") {
			if (_CONVERT_COMMAND!='') {
				define ('_CONVERT_COMMAND', 'convert');
				define ('_ROTATE_COMMAND', _CONVERT_COMMAND.' -rotate %t %src %dest');
			} else
				define ('_ROTATE_COMMAND', '');
			if (_ROTATE_COMMAND!=='') {
				$commande = str_replace(
					array('%t', '%src', '%dest'),
					array(
						$var_rot,
						escapeshellcmd($src),
						escapeshellcmd($dest)
					),
					_ROTATE_COMMAND);
				spip_log($commande);
				exec($commande);
			} else
				$dest = $src;
		}
	}
	else
		$dest = $src;

	$size_image = @getimagesize($dest);
	$largeur = $size_image[0];
	$hauteur = $size_image[1];

	// succes !
	if ($largeur>0 AND $hauteur>0) {
		sql_updateq('spip_documents', array('fichier' => set_spip_doc($dest), 'largeur'=>$largeur, 'hauteur'=>$hauteur), "id_document=$arg");
		if ($effacer) {
			spip_log("j'efface $effacer");
			spip_unlink($effacer);
		}
		// pipeline pour les plugins
		pipeline('post_edition',
			array(
				'args' => array(
					'table' => 'spip_documents',
					'table_objet' => 'documents',
					'spip_table_objet' => 'spip_documents',
					'type' =>'document',
					'id_objet' => $arg,
					'champs' => array('rotation'=>$r[2],'orientation'=>$var_rot,'fichier'=>$row),
					'serveur' => $serveur,
					'action'=>'tourner',
				),
				'data' => array('fichier'=>$row)
			)
		);
	}

}
Ejemplo n.º 11
0
function liberty_imagick0_rotate_image(&$pFileHash)
{
    $ret = FALSE;
    if (!empty($pFileHash['source_file']) && is_file($pFileHash['source_file'])) {
        $iImg = imagick_readimage($pFileHash['source_file']);
        if (!$iImg) {
            $pFileHash['error'] = $pFileHash['name'] . ' ' . tra("is not a known image file");
        } elseif (imagick_iserror($iImg)) {
            $pFileHash['error'] = imagick_failedreason($iImg) . imagick_faileddescription($iImg);
        } elseif (empty($pFileHash['degrees']) || !is_numeric($pFileHash['degrees'])) {
            $pFileHash['error'] = tra('Invalid rotation amount');
        } else {
            if (!imagick_rotate($iImg, $pFileHash['degrees'])) {
                $pFileHash['error'] .= imagick_failedreason($iImg) . imagick_faileddescription($iImg);
            }
            if (!imagick_writeimage($iImg, $pFileHash['source_file'])) {
                $pFileHash['error'] .= imagick_failedreason($iImg) . imagick_faileddescription($iImg);
            }
        }
    } else {
        $pFileHash['error'] = "No source file to resize";
    }
    return empty($pFileHash['error']);
}