search
HomeBackend DevelopmentPHP TutorialPHP中使用Imagick实现各种图片效果实例_php技巧

imagick是一个功能强大的图像处理库。 
说是翻译 其实就是简要介绍imagick 的主要功能的或者说是我觉得比较实用的功能函数的介绍 以及使用的例子。 
因为本人的英语水平有限,所以采用比较通俗或者说比较贴近应用化的语言来描述。 
先欣赏一组炫丽的效果:  
偏置图像:  
例子: 

复制代码 代码如下:

<?php  
ini_set(&#39;display_errors&#39;,1);  
header(&#39;Content-type: image/jpeg&#39;);  
$image = new Imagick(&#39;1.jpg&#39;);  
$image->rollImage(20,39);  
echo $image;  
?>

thumbnailImage($width,$height) 改变图片大小 
例子: 

复制代码 代码如下:

<?php  
ini_set(&#39;display_errors&#39;,1);  
header(&#39;Content-type: image/jpeg&#39;);  
$image = new Imagick(&#39;1.jpg&#39;);  
$image->thumbnailImage(100,0);  
echo $image;  
?>

addNoiseImage(int $noise_type [, int $channel= Imagick::CHANNEL_ALL ]); 
功能: 
Adds random noise to the image 
添加干扰素 

复制代码 代码如下:

Noise constants ( $noise_type 类型)  
imagick::NOISE_UNIFORM (integer)  
imagick::NOISE_GAUSSIAN (integer)  
imagick::NOISE_MULTIPLICATIVEGAUSSIAN (integer)  
imagick::NOISE_IMPULSE (integer)  
imagick::NOISE_LAPLACIAN (integer)  
imagick::NOISE_POISSON (integer)  
Channel constants ( $channel 类型)  
imagick::CHANNEL_UNDEFINED (integer)  
imagick::CHANNEL_RED (integer)  
imagick::CHANNEL_GRAY (integer)  
imagick::CHANNEL_CYAN (integer)  
imagick::CHANNEL_GREEN (integer)  
imagick::CHANNEL_MAGENTA (integer)  
imagick::CHANNEL_BLUE (integer)  
imagick::CHANNEL_YELLOW (integer)  
imagick::CHANNEL_ALPHA (integer)  
imagick::CHANNEL_OPACITY (integer)  
imagick::CHANNEL_MATTE (integer)  
imagick::CHANNEL_BLACK (integer)  
imagick::CHANNEL_INDEX (integer)  
imagick::CHANNEL_ALL (integer)

例子:

复制代码 代码如下:

<?php  
ini_set(&#39;display_errors&#39;,1);  
header(&#39;Content-type: image/jpeg&#39;);  
$image = new Imagick(&#39;1.jpg&#39;);  
$image->thumbnailImage(100,0);  
$image->addNoiseImage(imagick::NOISE_POISSON,imagick::CHANNEL_OPACITY);  
echo $image;  
?>

annotateImage 创建文本图像 

例子: 

复制代码 代码如下:

<?php  
$image = new Imagick();  
$draw = new ImagickDraw();  
$pixel = new ImagickPixel( &#39;gray&#39; );  
$image->newImage(800, 75, $pixel);  
$pixel->setColor(&#39;black&#39;);  
$draw->setFont(&#39;Bookman-DemiItalic&#39;);  
$draw->setFontSize( 30 );  
$image->annotateImage($draw, 10, 45, 0, &#39;The quick brown fox jumps over the lazy dog&#39;);  
$image->setImageFormat(&#39;png&#39;);  
header(&#39;Content-type: image/png&#39;);  
echo $image;  
?>

blurImage(float $radius , float $sigma [, int $channel ]) 
Adds blur filter to image 图像模糊度处理 
参数: 

复制代码 代码如下:

int $channel :  
imagick::CHANNEL_UNDEFINED (integer)  
imagick::CHANNEL_RED (integer)  
imagick::CHANNEL_GRAY (integer)  
imagick::CHANNEL_CYAN (integer)  
imagick::CHANNEL_GREEN (integer)  
imagick::CHANNEL_MAGENTA (integer)  
imagick::CHANNEL_BLUE (integer)  
imagick::CHANNEL_YELLOW (integer)  
imagick::CHANNEL_ALPHA (integer)  
imagick::CHANNEL_OPACITY (integer)  
imagick::CHANNEL_MATTE (integer)  
imagick::CHANNEL_BLACK (integer)  
imagick::CHANNEL_INDEX (integer)  
imagick::CHANNEL_ALL (integer)

复制代码 代码如下:

<?php  
ini_set(&#39;display_errors&#39;,1);  
header(&#39;Content-type: image/jpeg&#39;);  
$image = new Imagick(&#39;1.jpg&#39;);  
$image->blurImage(5,3);  
echo $image;  
?>

borderImage ( mixed $bordercolor , int $width , int $height ) 图片边框处理 
例子: 

复制代码 代码如下:

<?php  
ini_set(&#39;display_errors&#39;,1);  
header(&#39;Content-type: image/jpeg&#39;);  
$image = new Imagick(&#39;1.jpg&#39;);  
$color=new ImagickPixel();  
$color->setColor("rgb(220,220,220)");  
$image->borderImage($color,5,4);  
  
$image->blurImage(5,5,imagick::CHANNEL_GREEN);  
echo $image;  
?>

charcoalImage ( float $radius , float $sigma ) 图像素描处理 
参数说明: 
$radius :越小越薄。 
$sigma: 越大 墨越深 反之。 
例子: 

复制代码 代码如下:

<?php  
ini_set(&#39;display_errors&#39;,1);  
header(&#39;Content-type: image/jpeg&#39;);  
$image = new Imagick(&#39;1.jpg&#39;);  
$color=new ImagickPixel();  
$color->setColor("rgb(220,220,220)");  
$image->borderImage($color,5,4);  
$image->charcoalImage(0.0001,0.001);  
//$image->blurImage(5,5,imagick::CHANNEL_GREEN);  
echo $image;  
?>

chopImage ( int $width , int $height , int $x , int $y ) 
参数说明:删除一定范围的图像区域 
就不做参数说明,一看便知. 
 
colorizeImage( mixed $colorize , mixed $opacity )混合填充颜色 
$colorize 颜色 
$opacit 透明度 
例子: 

复制代码 代码如下:

<?php  
/* 
胶卷底片效果 
*/  
ini_set(&#39;display_errors&#39;,1);  
header(&#39;Content-type: image/jpeg&#39;);  
$image = new Imagick(&#39;1.jpg&#39;);  
$image->negateImage(false);  
$image->colorizeImage(&#39;#000&#39;,1.0);  
echo $image;  
?>

embossImage ( float $radius , float $sigma ) 
功能: 返回一个灰度级3D图像 不太好。 
例子: 

复制代码 代码如下:

<?php  
ini_set(&#39;display_errors&#39;,1);  
header(&#39;Content-type: image/jpeg&#39;);  
$image = new Imagick(&#39;1.jpg&#39;);  
$image->embossImage(1,1);  
echo $image;  
?>

(两张效果图)  
 
flipImage(void) 
功能: 创建图像倒影(垂直翻转) 
例子:

复制代码 代码如下:

<?php  
ini_set(&#39;display_errors&#39;,1);  
header(&#39;Content-type: image/jpeg&#39;);  
$image = new Imagick(&#39;1.jpg&#39;);  
$image->flipImage();  
echo $image;  
?>

flopImage ( void ) 
功能: 图像水平横向翻转 

复制代码 代码如下:

<?php  
ini_set(&#39;display_errors&#39;,1);  
header(&#39;Content-type: image/jpeg&#39;);  
$image = new Imagick(&#39;1.jpg&#39;);  
$image->flopImage();  
echo $image;  
?>

frameImage(mixed $matte_color,int $width, int $height,int $inner_bevel, int $outer_bevel) 
功能:创建3D图像边框 
参数说明: 
$matte_color:颜色 
$inner_bevel:边框内部倾斜度 
$outer_bevel:外部边框倾斜度 
例子:

复制代码 代码如下:

<?php  
ini_set(&#39;display_errors&#39;,1);  
header(&#39;Content-type: image/jpeg&#39;);  
$image = new Imagick(&#39;1.jpg&#39;);  
$color=new ImagickPixel();  
$color->setColor("rgb(220,220,220)");  
$image->frameImage($color,11,11,1,10);  
echo $image;  
?>

注意事项: 
$width(宽度)不能小于$inner_bevel(边框内部倾斜度)  
Imagick::gammaImage (float $gamma [,int $channel= Imagick::CHANNEL_ALL]) 
功能:调整图像灰度系数 
参数说明: 
float $gamma :灰度系数值 
$channel 默认为 Imagick::CHANNEL_ALL 
Imagick::CHANNEL_ALL 
例子 1: 

复制代码 代码如下:

<?php  
ini_set(&#39;display_errors&#39;,1);  
header(&#39;Content-type: image/jpeg&#39;);  
$image = new Imagick(&#39;1.jpg&#39;);  
$image->gammaImage(30);  
echo $image;  
?>

例子 2:

复制代码 代码如下:

<?php  
ini_set(&#39;display_errors&#39;,1);  
header(&#39;Content-type: image/jpeg&#39;);  
$image = new Imagick(&#39;1.jpg&#39;);  
$image->gammaImage(30);  
echo $image;  
?>

gaussianBlurImage ( float $radius , float $sigma [, int $channel= Imagick::CHANNEL_ALL ] ) 
功能:高斯模糊处理 类似于photo的高斯模糊 
参数说明: 
float $radius:高斯模糊的半径,像素,不包括中心象素。 
float $sigma :高斯的标准偏差,以像素为单位。我觉得这个参数最重要。 
int $channel :图像颜色模式。 

复制代码 代码如下:

<?php  
ini_set(&#39;display_errors&#39;,1);  
header(&#39;Content-type: image/jpeg&#39;);  
$image = new Imagick(&#39;1.jpg&#39;);  
$image->gaussianBlurImage(30,3);  
echo $image;  
?>

levelImage ( float $blackPoint , float $gamma , float $whitePoint [, int $channel= Imagick::CHANNEL_ALL ] ) 
功能: 调整图像的色阶(Adjusts the levels of an image) 
参数说明 

复制代码 代码如下:

<?php  
ini_set(&#39;display_errors&#39;,1);  
header(&#39;Content-type: image/jpeg&#39;);  
$image = new Imagick(&#39;1.jpg&#39;);  
$image->levelImage(4,4,4);  
echo $image;  
?>

例子2: 

复制代码 代码如下:

<?php  
ini_set(&#39;display_errors&#39;,1);  
header(&#39;Content-type: image/jpeg&#39;);  
$image = new Imagick(&#39;1.jpg&#39;);  
$image->levelImage(200,200,200,imagick::CHANNEL_GREEN);  
echo $image;  
?>

magnifyImage( void ) 
功能说明:简便的图像等比例放大2倍(Is a convenience method that scales an image proportionally to twice its original size. ) 
例子: 

复制代码 代码如下:

<?php  
ini_set(&#39;display_errors&#39;,1);  
header(&#39;Content-type: image/jpeg&#39;);  
$image = new Imagick(&#39;1.jpg&#39;);  
$image->magnifyImage ();  
echo $image;  
?>

medianFilterImage ( float $radius ) 
功能:特是的滤镜 有点像photoshop 调色刀滤镜 

复制代码 代码如下:

<?php  
ini_set(&#39;display_errors&#39;,1);  
header(&#39;Content-type: image/jpeg&#39;);  
$image = new Imagick(&#39;1.jpg&#39;);  
$color=new ImagickPixel();  
$color->setColor("rgb(220,220,220)");  
$image->medianFilterImage(5);  
echo $image;  
?>

minifyImage(void)  
功能:图小缩小一倍(Scales an image proportionally to half its size) 
例子: 

复制代码 代码如下:

<?php  
ini_set(&#39;display_errors&#39;,1);  
header(&#39;Content-type: image/jpeg&#39;);  
$image = new Imagick(&#39;1.jpg&#39;);  
$image->minifyImage();  
echo $image;  
?>

modulateImage ( float $brightness , float $saturation , float $hue ) 
功能:控制调整图像的 亮度、饱和度、色调。 
参数说明: 
float $brightness: 亮度 
float $saturation :饱和度 
float $hue 色调 
例子1: 

复制代码 代码如下:

<?php  
ini_set(&#39;display_errors&#39;,1);  
header(&#39;Content-type: image/jpeg&#39;);  
$image = new Imagick(&#39;1.jpg&#39;);  
$image->modulateImage(100,1,100);  
echo $image;  
?>

例子2:

复制代码 代码如下:

<?php  
ini_set(&#39;display_errors&#39;,1);  
header(&#39;Content-type: image/jpeg&#39;);  
$image = new Imagick(&#39;1.jpg&#39;);  
$image->modulateImage(250,1,250);  
echo $image;  
?>

motionBlurImagemotionBlurImage ( float $radius , float $sigma , float $angle [, int $channel= Imagick::CHANNEL_DEFAULT ] ) 
功能:模拟运动模糊(Simulates motion blur) ,类似photoshop的动感模糊滤镜功能 
参数说明: 
float $radius: 高斯 半径,不包过中心像素。 
float $sigma:标准偏差的高斯,以像素为单位。【重要参数】 
float $angle:模糊角度。 
int $channel:图像颜色模式。默认为 Imagick::CHANNEL_DEFAULT 
例子1: 

复制代码 代码如下:

<?php  
ini_set(&#39;display_errors&#39;,1);  
header(&#39;Content-type: image/jpeg&#39;);  
$image = new Imagick(&#39;1.jpg&#39;);  
$color=new ImagickPixel();  
$color->setColor("rgb(220,220,220)");  
$image->motionBlurImage (61,10,10);  
echo $image;  
?>

例子2: 

复制代码 代码如下:

<?php  
ini_set(&#39;display_errors&#39;,1);  
header(&#39;Content-type: image/jpeg&#39;);  
$image = new Imagick(&#39;1.jpg&#39;);  
$color=new ImagickPixel();  
$color->setColor("rgb(220,220,220)");  
$image->motionBlurImage (201,10,100);  
echo $image;  
?>

oilPaintImage ( float $radius ): 
功能说明: 模拟油画滤镜(Simulates an oil painting) 
例子: 

复制代码 代码如下:

<?php  
ini_set(&#39;display_errors&#39;,1);  
header(&#39;Content-type: image/jpeg&#39;);  
$image = new Imagick(&#39;1.jpg&#39;);  
$color=new ImagickPixel();  
$color->setColor("rgb(220,220,220)");  
$image->oilPaintImage(1);  
echo $image;  
?>

radialBlurImage ( float $angle [, int $channel= Imagick::CHANNEL_ALL ] ) 
功能: 径向模糊(Radial blurs an image) 

复制代码 代码如下:

<?php  
ini_set(&#39;display_errors&#39;,1);  
header(&#39;Content-type: image/jpeg&#39;);  
$image = new Imagick(&#39;1.jpg&#39;);  
$color=new ImagickPixel();  
$color->setColor("rgb(220,220,220)");  
$image->radialBlurImage(30);  
echo $image;  
?>

raiseImage ( int $width , int $height , int $x , int $y , bool $raise ) 
功能说明:创建3D图像按钮(Creates a simulated 3d button-like effect) 

复制代码 代码如下:

<?php  
ini_set(&#39;display_errors&#39;,1);  
header(&#39;Content-type: image/jpeg&#39;);  
$image = new Imagick(&#39;1.jpg&#39;);  
$color=new ImagickPixel();  
$color->setColor("rgb(220,220,220)");  
$image->raiseImage(10,10,3,5,6);  
echo $image;  
?>

附1:要求缩小图片尺寸、增加半透明边框,读入exif信息,按指定要求显示在图片上

复制代码 代码如下:

$towidth = &#39;500&#39;;  
$toheight = &#39;700&#39;; //设置图片调整大小时允许的最大宽度和高度  
$sourcefile = &#39;./b.jpg&#39;; //定义一个图像文件路径  
//$image->writeImage(&#39;./b.jpg.bak&#39;); //可以备份这个图片  
$myimage = new Imagick( $sourcefile ); //读入该图像文件  
$exifobject = my_exif( $myimage ); //自写函数,读取exif信息(拍摄数据),按自己的要求排列exif信息,返回对象  
//$myimage->setImageFormat(&#39;jpeg&#39;); //把图片转为jpg格式  
$myimage->setCompressionQuality( 100 ); //设置jpg压缩质量,1 - 100  
$myimage->enhanceImage(); //去噪点  
$sourcewidth = $myimage->getImageWidth(); //获取读入图像原始大小  
if ( $sourcewidth > $towidth )  
{  
  $myimage->scaleImage( $towidth, $toheight, true ); //调整图片大小  
}  
$myimage->raiseImage( 8, 8, 0, 0, 1 ); //加半透明边框  
$resizewidth = $myimage->getImageWidth(); //读出调整之后的图片大小  
$resizeheight = $myimage->getImageHeight();  
$drawback = new ImagickDraw(); //实例化一个绘画对象,绘制半透明黑色背景给exif信息用  
$drawback->setFillColor( new ImagickPixel(&#39;#000000&#39;) ); //设置填充颜色为黑色  
$drawback->setFillOpacity( 0.6 ); //填充透明度为0.6,参数0.1-1,1为不透明  
$drawback->rectangle( $resizewidth / 2 - 190, $resizeheight - 50, $resizewidth / 2 + 190, $resizeheight - 12 ); //绘制矩形参数,分别为左上角x、y,右下角x、y  
$myimage->drawImage( $drawback ); //确认到image中绘制该矩形框  
$draw = new ImagickDraw(); //实例化一个绘画对象,绘制exif文本信息嵌入图片中  
$draw->setFont( &#39;./xianhei.ttf&#39; ); //设置文本字体,要求ttf或者ttc字体,可以绝对或者相对路径  
$draw->setFontSize( 11 ); //设置字号  
$draw->setTextAlignment( 2 ); //文字对齐方式,2为居中  
$draw->setFillColor( &#39;#FFFFFF&#39; ); //文字填充颜色  
$myimage->annotateImage( $draw, $resizewidth / 2, $resizeheight - 39, 0, $exifobject->row1 ); //绘制第一行文本,居中  
$myimage->annotateImage( $draw, $resizewidth / 2, $resizeheight - 27, 0, $exifobject->row2 ); //绘制第二行文本,居中  
$myimage->annotateImage( $draw, $resizewidth / 2, $resizeheight - 15, 0, $exifobject->row3 ); //绘制第三行文本,居中  
/* Output the image with headers */  
header( &#39;Content-type: image/jpeg&#39; ); //php文件输出mime类型为jpeg图片  
echo $myimage; //在当前php页面输出图片  
//$image->writeImage(&#39;./b.new.jpg&#39;); //如果图片不需要在当前php程序中输出,使用写入图片到磁盘函数,上面的设置header也可以去除  
$myimage->clear();  
$myimage->destroy(); //释放资源  
//自写函数,读取exif信息,返回对象  
function my_exif( $myimage )  
{  
  $exifArray = array( &#39;exif:Model&#39; => &#39;未知&#39;, &#39;exif:DateTimeOriginal&#39; => &#39;未知&#39;, &#39;exif:ExposureProgram&#39; => &#39;未知&#39;, &#39;exif:FNumber&#39; => &#39;0/10&#39;, &#39;exif:ExposureTime&#39; => &#39;0/10&#39;, &#39;exif:ISOSpeedRatings&#39; => &#39;未知&#39;,  
    &#39;exif:MeteringMode&#39; => &#39;未知&#39;, &#39;exif:Flash&#39; => &#39;关闭闪光灯&#39;, &#39;exif:FocalLength&#39; => &#39;未知&#39;, &#39;exif:ExifImageWidth&#39; => &#39;未知&#39;, &#39;exif:ExifImageLength&#39; => &#39;未知&#39; ); //初始化部分信息,防止无法读取照片exif信息时运算发生错误  
  $exifArray = $myimage->getImageProperties( "exif:*" ); //读取图片的exif信息,存入$exifArray数组  
  //如果需要显示原数组可以使用print_r($exifArray);  
  $r->row1 = &#39;相机:&#39; . $exifArray[&#39;exif:Model&#39;];  
  $r->row1 = $r->row1 . &#39; 拍摄时间:&#39; . $exifArray[&#39;exif:DateTimeOriginal&#39;];  
  switch ( $exifArray[&#39;exif:ExposureProgram&#39;] )  
  {  
    case 1:  
      $exifArray[&#39;exif:ExposureProgram&#39;] = "手动(M)";  
      break; //Manual Control  
    case 2:  
      $exifArray[&#39;exif:ExposureProgram&#39;] = "程序自动(P)";  
      break; //Program Normal  
    case 3:  
      $exifArray[&#39;exif:ExposureProgram&#39;] = "光圈优先(A,Av)";  
      break; //Aperture Priority  
    case 4:  
      $exifArray[&#39;exif:ExposureProgram&#39;] = "快门优先(S,Tv)";  
      break; //Shutter Priority  
    case 5:  
      $exifArray[&#39;exif:ExposureProgram&#39;] = "慢速快门";  
      break; //Program Creative (Slow Program)  
    case 6:  
      $exifArray[&#39;exif:ExposureProgram&#39;] = "运动模式";  
      break; //Program Action(High-Speed Program)  
    case 7:  
      $exifArray[&#39;exif:ExposureProgram&#39;] = "人像";  
      break; //Portrait  
    case 8:  
      $exifArray[&#39;exif:ExposureProgram&#39;] = "风景";  
      break; //Landscape  
    default:  
      $exifArray[&#39;exif:ExposureProgram&#39;] = "其它";  
  }  
  $r->row1 = $r->row1 . &#39; 模式:&#39; . $exifArray[&#39;exif:ExposureProgram&#39;];  
  $exifArray[&#39;exif:FNumber&#39;] = explode( &#39;/&#39;, $exifArray[&#39;exif:FNumber&#39;] );  
  $exifArray[&#39;exif:FNumber&#39;] = $exifArray[&#39;exif:FNumber&#39;][0] / $exifArray[&#39;exif:FNumber&#39;][1];  
  $r->row2 = &#39;光圈:F/&#39; . $exifArray[&#39;exif:FNumber&#39;];  
  $exifArray[&#39;exif:ExposureTime&#39;] = explode( &#39;/&#39;, $exifArray[&#39;exif:ExposureTime&#39;] );  
  if ( ($exifArray[&#39;exif:ExposureTime&#39;][0] / $exifArray[&#39;exif:ExposureTime&#39;][1]) >= 1 )  
  {  
    $exifArray[&#39;exif:ExposureTime&#39;] = sprintf( "%.1fs", (float)$exifArray[&#39;exif:ExposureTime&#39;][0] / $exifArray[&#39;exif:ExposureTime&#39;][1] );  
  } else  
  {  
    $exifArray[&#39;exif:ExposureTime&#39;] = sprintf( "1/%ds", $exifArray[&#39;exif:ExposureTime&#39;][1] / $exifArray[&#39;exif:ExposureTime&#39;][0] );  
  }  
  $r->row2 = $r->row2 . &#39; 快门:&#39; . $exifArray[&#39;exif:ExposureTime&#39;];  
  $r->row2 = $r->row2 . &#39; ISO:&#39; . $exifArray[&#39;exif:ISOSpeedRatings&#39;];  
  $exifArray[&#39;exif:ExposureBiasValue&#39;] = explode( "/", $exifArray[&#39;exif:ExposureBiasValue&#39;] );  
  $exifArray[&#39;exif:ExposureBiasValue&#39;] = sprintf( "%1.1feV", ((float)$exifArray[&#39;exif:ExposureBiasValue&#39;][0] / $exifArray[&#39;exif:ExposureBiasValue&#39;][1] * 100) / 100 );  
  if ( (float)$exifArray[&#39;exif:ExposureBiasValue&#39;] > 0 )  
  {  
    $exifArray[&#39;exif:ExposureBiasValue&#39;] = "+" . $exifArray[&#39;exif:ExposureBiasValue&#39;];  
  }  
  $r->row2 = $r->row2 . &#39; 补偿:&#39; . $exifArray[&#39;exif:ExposureBiasValue&#39;];  
  switch ( $exifArray[&#39;exif:MeteringMode&#39;] )  
  {  
    case 0:  
      $exifArray[&#39;exif:MeteringMode&#39;] = "未知";  
      break;  
    case 1:  
      $exifArray[&#39;exif:MeteringMode&#39;] = "矩阵";  
      break;  
    case 2:  
      $exifArray[&#39;exif:MeteringMode&#39;] = "中央重点平均";  
      break;  
    case 3:  
      $exifArray[&#39;exif:MeteringMode&#39;] = "点测光";  
      break;  
    case 4:  
      $exifArray[&#39;exif:MeteringMode&#39;] = "多点测光";  
      break;  
    default:  
      $exifArray[&#39;exif:MeteringMode&#39;] = "其它";  
  }  
  $r->row2 = $r->row2 . &#39; 测光:&#39; . $exifArray[&#39;exif:MeteringMode&#39;];  
  switch ( $exifArray[&#39;exif:Flash&#39;] )  
  {  
    case 1:  
      $exifArray[&#39;exif:Flash&#39;] = "开启闪光灯";  
      break;  
  }  
  $r->row2 = $r->row2 . &#39; &#39; . $exifArray[&#39;exif:Flash&#39;];  
  if ( $exifArray[&#39;exif:FocalLengthIn35mmFilm&#39;] )  
  {  
    $r->row3 = &#39;等效焦距:&#39; . $exifArray[&#39;exif:FocalLengthIn35mmFilm&#39;] . "mm";  
  } else  
  {  
    $exifArray[&#39;exif:FocalLength&#39;] = explode( "/", $exifArray[&#39;exif:FocalLength&#39;] );  
    $exifArray[&#39;exif:FocalLength&#39;] = sprintf( "%4.1fmm", (double)$exifArray[&#39;exif:FocalLength&#39;][0] / $exifArray[&#39;exif:FocalLength&#39;][1] );  
    $r->row3 = &#39;焦距:&#39; . $exifArray[&#39;exif:FocalLength&#39;];  
  }  
  $r->row3 = $r->row3 . &#39; 原始像素:&#39; . $exifArray[&#39;exif:ExifImageWidth&#39;] . &#39;x&#39; . $exifArray[&#39;exif:ExifImageLength&#39;] . &#39;px&#39;;  
  if ( $exifArray[&#39;exif:Software&#39;] )  
  {  
    $r->row3 = $r->row3 . &#39; 后期:&#39; . $exifArray[&#39;exif:Software&#39;];  
  }  
  return $r;  
}

附2:处理图片水印

复制代码 代码如下:

<?php  
//获取水印图片  
$logo = new Imagick("logo.png");  
$logo->setImageResolution(0.01,0.03);  
  
//创建一个Imagick对象,同时获取要处理的源图  
$im = new Imagick( "old_large_img_2.jpg" );  
  
//获取源图片宽和高  
$srcWH = $im->getImageGeometry();  
  
//图片等比例缩放宽和高设置  
if($srcWH[&#39;width&#39;]>710){  
$srcW[&#39;width&#39;] = 710;  
$srcH[&#39;height&#39;] = $srcW[&#39;width&#39;]/$srcWH[&#39;width&#39;]*$srcWH[&#39;height&#39;];  
}else{  
$srcW[&#39;width&#39;] = $srcWH[&#39;width&#39;];  
$srcH[&#39;height&#39;] = $srcWH[&#39;height&#39;];  
}  
  
//按照比例进行缩放  
$im->thumbnailImage( $srcW[&#39;width&#39;], $srcH[&#39;height&#39;], true );  
  
// 按照缩略图大小创建一个有颜色的图片  
$canvas = new Imagick();  
$canvas->newImage( $srcW[&#39;width&#39;], $srcH[&#39;height&#39;], &#39;black&#39;, &#39;jpg&#39; ); //pink,black  
  
//添加水印  
$im->compositeImage($logo,Imagick::COMPOSITE_OVER,$srcW[&#39;width&#39;]-280,$srcH[&#39;height&#39;]-77);  
$canvas->setcompressionquality(91);  
//合并图片  
$canvas->compositeImage( $im, imagick::COMPOSITE_OVER, 0, 0);  
  
//输出图片  
header( "Content-Type: image/jpg" );  
echo $canvas;    
  
//生成图片  
$canvas->writeImage( "test_img/old_large_img_2_96.jpg" );  
?>

 

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP: An Introduction to the Server-Side Scripting LanguagePHP: An Introduction to the Server-Side Scripting LanguageApr 16, 2025 am 12:18 AM

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

PHP and the Web: Exploring its Long-Term ImpactPHP and the Web: Exploring its Long-Term ImpactApr 16, 2025 am 12:17 AM

PHP has shaped the network over the past few decades and will continue to play an important role in web development. 1) PHP originated in 1994 and has become the first choice for developers due to its ease of use and seamless integration with MySQL. 2) Its core functions include generating dynamic content and integrating with the database, allowing the website to be updated in real time and displayed in personalized manner. 3) The wide application and ecosystem of PHP have driven its long-term impact, but it also faces version updates and security challenges. 4) Performance improvements in recent years, such as the release of PHP7, enable it to compete with modern languages. 5) In the future, PHP needs to deal with new challenges such as containerization and microservices, but its flexibility and active community make it adaptable.

Why Use PHP? Advantages and Benefits ExplainedWhy Use PHP? Advantages and Benefits ExplainedApr 16, 2025 am 12:16 AM

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

Debunking the Myths: Is PHP Really a Dead Language?Debunking the Myths: Is PHP Really a Dead Language?Apr 16, 2025 am 12:15 AM

PHP is not dead. 1) The PHP community actively solves performance and security issues, and PHP7.x improves performance. 2) PHP is suitable for modern web development and is widely used in large websites. 3) PHP is easy to learn and the server performs well, but the type system is not as strict as static languages. 4) PHP is still important in the fields of content management and e-commerce, and the ecosystem continues to evolve. 5) Optimize performance through OPcache and APC, and use OOP and design patterns to improve code quality.

The PHP vs. Python Debate: Which is Better?The PHP vs. Python Debate: Which is Better?Apr 16, 2025 am 12:03 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on the project requirements. 1) PHP is suitable for web development, easy to learn, rich community resources, but the syntax is not modern enough, and performance and security need to be paid attention to. 2) Python is suitable for data science and machine learning, with concise syntax and easy to learn, but there are bottlenecks in execution speed and memory management.

PHP's Purpose: Building Dynamic WebsitesPHP's Purpose: Building Dynamic WebsitesApr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP: Handling Databases and Server-Side LogicPHP: Handling Databases and Server-Side LogicApr 15, 2025 am 12:15 AM

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

How do you prevent SQL Injection in PHP? (Prepared statements, PDO)How do you prevent SQL Injection in PHP? (Prepared statements, PDO)Apr 15, 2025 am 12:15 AM

Using preprocessing statements and PDO in PHP can effectively prevent SQL injection attacks. 1) Use PDO to connect to the database and set the error mode. 2) Create preprocessing statements through the prepare method and pass data using placeholders and execute methods. 3) Process query results and ensure the security and performance of the code.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft