PHP代码
- <?php
- $image = "pic.jpg" ;
- $img = GetImageSize ( $image );
- switch ( $img [2]){
- case 1:
- $im =ImageCreateFromGif( $image );
- break ;
- case 2:
- $im =ImageCreateFromJPEG( $image );
- break ;
- case 3:
- $im =ImageCreateFrompng( $image );
- break ;
- }
- $logo = "logo.gif" ;
- $ing = GetImageSize ( $logo );
- switch ( $ing [2]){
- case 1:
- $in =ImageCreateFromGif( $logo );
- break ;
- case 2:
- $in =ImageCreateFromJPEG( $logo );
- break ;
- case 3:
- $in =ImageCreateFrompng( $logo );
- break ;
- }
- //载入水印图片(原图,水印图,显示位置X坐标,显示位置Y坐标,水印起始X坐标,水印起始Y坐标,水印宽,水印高)
- imagecopy( $im , $in ,0,0,0,0, '330' , "200" );
- //分配字体颜色
- /*$te =imagecolorallocate ($im, 255, 255,255);
- //写入中文(图,字号,倾斜度,X坐标,Y坐标, 字体,汉字)
- imagettftext($im,12,0,20,20,$te,"simhei.ttf"," 中国");*/
- //剪切图
- $new =@imagecreatetruecolor (200,200); //新建真色彩图
- //剪切(新图,原始图,新图X,新图Y,原图开始X,原图开始Y,原图宽,原图高)
- ImageCopyResized( $new , $im ,0,0,0,0,200,200, $img [0], $img [1]);
- // header ("Content-type: image/jpeg");
- imagejpeg ( $new , 'small.jpg' );
- ?>