图片指定大小然后由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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot 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

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 English version
Recommended: Win version, supports code prompts!

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment