PHP 处理图片
有个上传图片的功能
如何每次把上传的图片大小控制在200K以下?
只能更改图片的尺寸吗?
其实图片的像素和尺寸和清晰度等都有什么联系。。
回复讨论(解决方案)
php.ini里有upload_max_filesize = 128M 可以设置大小吧!而且在html页面也可以设置中的value来限制大小
无压缩图片大概一个像素3字节(RGB),jpg约为1/6大小,当然可以更小,但失真更大就是了
可以重采样使用更大压缩比减少字节数,但一般服务器不做这事,因为大量操作很吃资源的
php.ini里有upload_max_filesize = 128M 可以设置大小吧!而且在html页面也可以设置中的value来限制大小
不是不让上传,而是把上传的图片改小
gd库生成缩略图就是了
gd库生成缩略图就是了
是不是只能指定尺寸,但不能保证一定在200K以下?
可以的。尺寸会影响大小。
控制一下压缩比例,因为有的图片像素太大的话,比例缩略到指定比例也不一定会小于200k,所以要控制你最大上传图片的大小缩略到200k的最佳比例...
从目前流行的图片采集设备上看,200K 只不过是一张普通邮票
清晰度是指表示已知大小的目标所耗费的像素素,当然是越多越清晰
比如,头发的直径约在70~100μm之间
你用一个像素表示,那么只是一条细线
你用100个像素表示的话,你将能看到发身上的鳞片
比如,头发的直径约在70~100μm之间
你用一个像素表示,那么只是一条细线
你用100个像素表示的话,你将能看到发身上的鳞片
平时用相机照出来的图片,在电脑里用查看图片的软件打开看到应该不是图片的实际尺寸?
如果用 100个像素表示头发,那图片本身尺寸是不是很大?
其实我想问的就是像素和图片尺寸的联系。
如果用 100个像素表示头发,那图片本身尺寸是不是很大?
那也不一定,如果那个图片中就只有一根头发,那不也就只有100个像素吗?
建议你先复习一下 分辨率 的知识
像素和 图片尺寸的关系是单元和总体的关系
像素和 图片文件尺寸(字节数)的关系我在#2说了
一幅1024x500像素的无损全彩(24bit)图片就是1500k再加文件头,jpg(非jpg2000)就大概是无损的1/6约250k
说“大概”,“约”是因为jpg有多级压缩率,每像素的颜色值也有影响,故字节数不定
同样像素的“万花筒”和纯色图片,均使用24bit采样,两者无损图片格式的字节数一样,但jpg格式后者字节数就小很多

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.
