search
HomeCMS TutorialPHPCMSHow to compress images with phpcms

phpcms method of compressing images: first find and open the "extention.func.php" file; then write an automatic compression method in the public class; finally pass the statement "{compress ($rs['thumb' ])}" can be called directly in the html page.

How to compress images with phpcms

phpcms automatic image compression function

Write an automatic compression method in the public class:

phpcms\libs\functions\extention.func.php
**
@param $imgName
@return mixed|string
$imgpath 原图存放地址
$thumbpath 压缩后图片存放路径
*/
function compress ($imgName){
imgPath=PHPCMSPATH.trim(imgPath = PHPCMS_PATH . trim(imgPath=PHPCMS 
P
 ATH.trim(imgName, ‘/’);
$Patharray = explode(’/’, $imgName);
fileName=end(fileName = end(fileName=end(Patharray);
//创建thumb文件夹,保存压缩后的图片
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(file 
e
 xists(thumbPath)) {
return APP_PATH . ‘uploadfile/thumb/’ . $fileName;
}else{
src=imagecreatefromjpeg(src = imagecreatefromjpeg(src=imagecreatefromjpeg(imgPath);
srcw=imagesx(src_w = imagesx(src 
w
 =imagesx(src);
srch=imagesy(src_h = imagesy(src 
h
 =imagesy(src);
//设置缩略图大小
$dst_w = $src_w1;
$dst_h = $src_h1;
dst=imagecreatetruecolor(dst = imagecreatetruecolor(dst=imagecreatetruecolor(dst_w,dsth);//图片采样复制imagecopyresampled(dst_h);//图片采样复制imagecopyresampled(dst 
h
 );//图片采样复制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);//保存缩略图imagejpeg(src_h);//保存缩略图imagejpeg(src 
h
 );//保存缩略图imagejpeg(dst,thumbPath);//销毁资源imagedestroy(thumbPath);//销毁资源imagedestroy(thumbPath);//销毁资源imagedestroy(src);
imagedestroy($dst);
thumbPath=strreplace(PHPCMSPATH,"/",thumbPath = str_replace(PHPCMS_PATH,"/",thumbPath=str 
r
 eplace(PHPCMS 
P
 ATH,"/",thumbPath);
return $thumbPath;
}
}

How to compress images with phpcms

How to compress images with phpcms

Recommendation: "phpcms tutorial"

Call directly in the html page

{compress ($rs[‘thumb’])}

The above is the detailed content of How to compress images with phpcms. For more information, please follow other related articles on the PHP Chinese website!

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

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)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools