In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to use phpcms to compress pictures, the code is concise and easy to understand, it can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
Phpcms compression method: first find and open the "extention.func.php" file; then write an automatic compression method in the public class; finally, through the statement "{compress ($rs ['thumb'])}" directly in the html page can be called.
Phpcms image automatic compression function
Write an automatic compression method in the public class:
Phpcms\ libs\ functions\ extention.func.php**@param $imgName@return mixed | string$imgpath original image storage address $thumbpath compressed image storage path * / function compress ($imgName) {imgPath=PHPCMSPATH.trim (imgPath=PHPCMS _ PATH. Trim (imgPath=PHPCMS P ATH.trim (imgName,'/'); $Patharray = explode ('/', $imgName); fileName=end (Patharray); / / create a thumb folder to save the compressed image header ("Content-type:text/html;charset=utf-8"); $path= "/ uploadfile/thumb/"; dirPath=PHPCMSPATH.dirPath = PHPCMS_PATH.dirPath=PHPCMS P ATH.path;if (! is_dir (KaTeX parse error: Expected'}', got 'EOF' at end of input: … H) {mkdir (dirPath,0777,true);} $thumbPath = PHPCMS_PATH. 'uploadfile/thumb/'. FileName;if (fileexists (fileName;if (file_exists) (fileName;if (fileexists (thumbPath)) {return APP_PATH. 'uploadfile/thumb/'. $fileName;} else {src=imagecreatefromjpeg (imgPath); srcw=imagesx (src_w = imagesx (srcw=imagesx (src); srch=imagesy (src_h = imagesy (srch=imagesy (src)); / / set thumbnail size $dst_w = $src_w1;$dst_h = $src_h2;dst=imagecreatetruecolor (dst_w,dsth); / / Image sampling copy imagecopyresampled (dst_h); / / Image sampling copy imagecopyresampled (dsth)) / / copy imagecopyresampled (dst,src,0,0,0,0,src,0,0,0,0,src,0,0,0,0,dst_w,dsth,dst_h,dst h, src_w,srch); / / Save thumbnail imagejpeg (src_h); / / Save thumbnail imagejpeg (srch); / / Save thumbnail imagejpeg (dst,thumbPath); / / destroy resource imagedestroy (src); imagedestroy ($dst) ThumbPath=strreplace (PHPCMSPATH, "/", thumbPath=str _ replace (PHPCMS_PATH, "/", thumbPath=strreplace (PHPCMSPATH, "/", thumbPath); return $thumbPath;}}
Call directly from the html page
{compress ($rs ['thumb'])} the above is how to compress pictures with phpcms. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.