search
Homephp教程php手册php获得图像长宽、大小等属性

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 当我们在使用PHP开发用户中心时,肯定会有用户上传头像这一功能,或者在开发其他交互功能需要上传图片时,我们都需要知道用户上传的图片是否满足我们的要求,这里给大家分享一个简单的获取图像属性的

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

  当我们在使用PHP开发用户中心时,肯定会有用户上传头像这一功能,或者在开发其他交互功能需要上传图片时,我们都需要知道用户上传的图片是否满足我们的要求,这里给大家分享一个简单的获取图像属性的PHP自定义函数,希望能给大家带来帮助,这个函数也是网上一位网友写的,UncleToo测试过了,效果还不错,使用很方便。

  代码:

  

  /**

  * 取得图像信息

  *

  * @param string $image 图像文件名

  *

  * @return mixed

  */

  function getImageInfo($image) {

  $imageInfo = getimagesize($image);

  if ($imageInfo !== FALSE) {

  $imageType = strtolower(substr(image_type_to_extension($imageInfo[2]), 1));

  $imageSize = filesize($image);

  $info = array(

  "width" => $imageInfo[0],

  "height" => $imageInfo[1],

  "type" => $imageType,

  "size" => $imageSize,

  "mime" => $imageInfo['mime']

  );

  return $info;

  } else {

  return FALSE;

  }

  }

  ?>

  调用示例:

  1

  2

  3

  4

  

  $info = getImageInfo('123.jpg');

  var_dump($info);

  ?>

  输出结果:

  array(5) {

  ["width"]=>

  int(614)

  ["height"]=>

  int(850)

  ["type"]=>

  string(4) "jpeg"

  ["size"]=>

  int(597066)

  ["mime"]=>

  string(10) "image/jpeg"

  }

  这里输出的信息和下面图片展示的信息是一致的。

  图片信息:

php获得图像长宽、大小等属性

php获得图像长宽、大小等属性

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

Video Face Swap

Video Face Swap

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

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

mPDF

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),

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools