Home  >  Article  >  Backend Development  >  Add watermark to php pictures, cut avatar pictures and automatically zoom_PHP tutorial

Add watermark to php pictures, cut avatar pictures and automatically zoom_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:09:07958browse

An example of PHP image watermarking, avatar cutting and automatic scaling code. It can generate a rendering of a specified size from the image you upload and can automatically cut the image. See the example below.

An example of PHP tutorial on adding watermarks to pictures, cutting avatar pictures and automatic scaling code. It can generate a rendering of a specified size from the picture you upload and can automatically cut the picture. See the example below.





Upload file test

< ;body>

">
< ;input type="file" name="upload" id="upload" onchange="preview()"; />






http://code.google. com/p/queryphp/downloads/list

img class in frameworklibimg.class.php

/*
php image watermark, cut avatar image and Automatic scaling code

*/

class uploadrouter extends controller{
function index()
{
//Output upload form, see view file
}
function webimages()
{
print_r($_files);
$img=c("img");
$img->setinfo( //Set upload file attributes Array ("" files "= & gt;" upload ", // Upload the file box name name
" uploadPath "= & gt; $ globals ['config'] ['webprojectPath'." Upimages /", / /" / / Upload directory
"icopath"=>$globals['config']['webprojectpath']."upimages/", //If the small image directory is not set, the upload directory will be used "icowidth"=> ;"128", //Small image width
 "icoheight"=>"98", //Small image height
 "fangpath"=>$globals['config']['webprojectpath']. "upimages/_ico/", //Cut the square image, that is, cut the avatar, etc.
             "fangsize"=>"75", //How big is the square image? If the square image is set, the square image will be generated when uploading. Do not set it
"nzsize"=>"180", //Automatically set width or height not to exceed this
"uploadsize"=>420000 //Upload image size
)
) ->setbasename($_files['upload']['name'],true)->init();//,'size_ico','auto_ico','fix_ico','fill_size''fix_side'
                   // You can set the setbasename name yourself, otherwise the date name will be automatically generated, which will automatically change the Chinese to Pinyin and filter, and finally initialize init() >upload(array('fix_side'))) //Uploaded, set whether to generate a small picture. There are many formats. If it is empty, only the image will be uploaded and the others will be ignored.
{
echo("Upload successful");
}else{
echo("Upload failed");
echo $img->message;
}
return false;
}
}


?>


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444842.htmlTechArticleAn example of adding watermark to php pictures, cutting avatar pictures and automatic scaling code, he can add pictures you upload Generate renderings of specified sizes and automatically cut images. See examples below...
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