?? gd.php
字號:
imagepalettecopy($img2,$img);
$mask = imagecolorresolve($img2,$color_mask[0],$color_mask[1],$color_mask[2]);
// use simple lines copy for axes angles
switch((int)($angle)){
case 0:
imagefill ($img2, 0, 0,$mask);
for ($y=0; $y < $max_y; $y++) {
for ($x = $min_x; $x < $max_x; $x++){
$c = @imagecolorat ( $img, $x, $y);
imagesetpixel($img2,$x+$x_offset,$y+$y_offset,$c);
}
}
break;
case 90:
imagefill ($img2, 0, 0,$mask);
for ($x = $min_x; $x < $max_x; $x++){
for ($y=$min_y; $y < $max_y; $y++) {
$c = imagecolorat ( $img, $x, $y);
imagesetpixel($img2,$max_y-$y-1,$x,$c);
}
}
break;
case 180:
imagefill ($img2, 0, 0,$mask);
for ($y=0; $y < $max_y; $y++) {
for ($x = $min_x; $x < $max_x; $x++){
$c = @imagecolorat ( $img, $x, $y);
imagesetpixel($img2, $max_x2-$x-1, $max_y2-$y-1, $c);
}
}
break;
case 270:
imagefill ($img2, 0, 0,$mask);
for ($y=0; $y < $max_y; $y++) {
for ($x = $max_x; $x >= $min_x; $x--){
$c = @imagecolorat ( $img, $x, $y);
imagesetpixel($img2,$y,$max_x-$x-1,$c);
}
}
break;
// simple reverse rotation algo
default:
$i=0;
for ($y = $min_y2; $y < $max_y2; $y++){
// Algebra :)
$x2 = round((($min_x2-$x1) * $cosT) + (($y-$y1) * $sinT + $x1),0);
$y2 = round((($y-$y1) * $cosT - ($min_x2-$x1) * $sinT + $y1),0);
for ($x = $min_x2; $x < $max_x2; $x++){
// Check if we are out of original bounces, if we are
// use the default color mask
if ( $x2>=0 && $x2<$max_x && $y2>=0 && $y2<$max_y ){
$c = imagecolorat ( $img, $x2, $y2);
} else {
$c = $mask;
}
imagesetpixel($img2,$x+$x_offset,$y+$y_offset,$c);
// round verboten!
$x2 += $cosT;
$y2 -= $sinT;
}
}
break;
}
$this->old_image = $this->imageHandle;
$this->imageHandle = $img2;
return true;
}
/**
* Resize Action
*
* For GD 2.01+ the new copyresampled function is used
* It uses a bicubic interpolation algorithm to get far
* better result.
*
* @param $new_x int new width
* @param $new_y int new height
*
* @return true on success or pear error
* @see PEAR::isError()
*/
function _resize($new_x, $new_y) {
if ($this->resized === true) {
return false; /*PEAR::raiseError('You have already resized the image without saving it. Your previous resizing will be overwritten', null, PEAR_ERROR_TRIGGER, E_USER_NOTICE);*/
}
if(function_exists('ImageCreateTrueColor')){
$new_img =ImageCreateTrueColor($new_x,$new_y);
} else {
$new_img =ImageCreate($new_x,$new_y);
}
if(function_exists('ImageCopyResampled')){
ImageCopyResampled($new_img, $this->imageHandle, 0, 0, 0, 0, $new_x, $new_y, $this->img_x, $this->img_y);
} else {
ImageCopyResized($new_img, $this->imageHandle, 0, 0, 0, 0, $new_x, $new_y, $this->img_x, $this->img_y);
}
$this->old_image = $this->imageHandle;
$this->imageHandle = $new_img;
$this->resized = true;
$this->new_x = $new_x;
$this->new_y = $new_y;
return true;
}
/**
* Crop the image
*
* @param int $crop_x left column of the image
* @param int $crop_y top row of the image
* @param int $crop_width new cropped image width
* @param int $crop_height new cropped image height
*/
function crop($new_x, $new_y, $new_width, $new_height)
{
if(function_exists('ImageCreateTrueColor')){
$new_img =ImageCreateTrueColor($new_width,$new_height);
} else {
$new_img =ImageCreate($new_width,$new_height);
}
if(function_exists('ImageCopyResampled')){
ImageCopyResampled($new_img, $this->imageHandle, 0, 0, $new_x, $new_y,$new_width,$new_height,$new_width,$new_height);
} else {
ImageCopyResized($new_img, $this->imageHandle, 0, 0, $new_x, $new_y, $new_width,$new_height,$new_width,$new_height);
}
$this->old_image = $this->imageHandle;
$this->imageHandle = $new_img;
$this->resized = true;
$this->new_x = $new_x;
$this->new_y = $new_y;
return true;
}
/**
* Flip the image horizontally or vertically
*
* @param boolean $horizontal true if horizontal flip, vertical otherwise
*/
function flip($horizontal)
{
if(!$horizontal) {
$this->rotate(180);
}
$width = imagesx($this->imageHandle);
$height = imagesy($this->imageHandle);
for ($j = 0; $j < $height; $j++) {
$left = 0;
$right = $width-1;
while ($left < $right) {
//echo " j:".$j." l:".$left." r:".$right."\n<br>";
$t = imagecolorat($this->imageHandle, $left, $j);
imagesetpixel($this->imageHandle, $left, $j, imagecolorat($this->imageHandle, $right, $j));
imagesetpixel($this->imageHandle, $right, $j, $t);
$left++; $right--;
}
}
return true;
}
/**
* Adjust the image gamma
*
* @param float $outputgamma
*
* @return none
*/
function gamma($outputgamma=1.0) {
ImageGammaCorrect($this->imageHandle, 1.0, $outputgamma);
}
/**
* Save the image file
*
* @param $filename string the name of the file to write to
* @param $quality int output DPI, default is 85
* @param $types string define the output format, default
* is the current used format
*
* @return none
*/
function save($filename, $type = '', $quality = 85)
{
$type = $type==''? $this->type : $type;
$functionName = 'image' . $type;
if(function_exists($functionName))
{
$this->old_image = $this->imageHandle;
if($type=='jpeg')
$functionName($this->imageHandle, $filename, $quality);
else
$functionName($this->imageHandle, $filename);
$this->imageHandle = $this->old_image;
$this->resized = false;
}
} // End save
/**
* Display image without saving and lose changes
*
* @param string type (JPG,PNG...);
* @param int quality 75
*
* @return none
*/
function display($type = '', $quality = 75)
{
if ($type != '') {
$this->type = $type;
}
$functionName = 'Image' . $this->type;
if(function_exists($functionName))
{
header('Content-type: image/' . strtolower($this->type));
$functionName($this->imageHandle, '', $quality);
$this->imageHandle = $this->old_image;
$this->resized = false;
ImageDestroy($this->old_image);
$this->free();
}
}
/**
* Destroy image handle
*
* @return none
*/
function free()
{
if ($this->imageHandle){
ImageDestroy($this->imageHandle);
}
}
} // End class ImageGD
?>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -