图片指定大小然后由php相关函数来实现图片裁剪功能,前段的js效果在这里就不介绍了,大家可以到网上找有很多这类代码,我只整理了php操作部份。
方法一
代码如下 | 复制代码 |
图片裁剪缩放函数,支持方位裁剪和自定义坐标裁剪 |
附件是一个有样例图片的测试demo。
不过,这个函数不支持动态gif图片的裁剪缩放。
方法二,
代码如下 | 复制代码 |
list($src_w,$src_h)=getimagesize($src_img); // 获取原图尺寸 if($src_scale>=$dst_scale) |
方法三
根据自定义的目标图, 按目标图高宽比裁剪、缩放源图.
传入参数:
代码如下 | 复制代码 |
$source_path string 源图路径 $target_width integer 目标图宽度 $target_height integer 目标图高度 支持图片类型: image/gif, image/jpeg, image/png. function imagecropper($source_path, $target_width, $target_height) // 源图过高 switch ($source_mime) case 'image/jpeg': case 'image/png': default: $target_image = imagecreatetruecolor($target_width, $target_height); // 裁剪 header('Content-Type: image/jpeg'); |

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6
Visual web development tools

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

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment