Home > Backend Development > PHP Tutorial > php怎么获取图片的高度和宽度?

php怎么获取图片的高度和宽度?

PHPz
Release: 2020-09-04 14:07:46
Original
3503 people have browsed it

php怎么获取图片的高度和宽度?

php获取图片的高度和宽度的方法:

在PHP中,可以使用imagesx()函数获取图片的宽度,使用imagesy()函数获取图片的高度。

PHP 获取图像宽度函数:imagesx()

imagesx() 函数用于获取图像的宽度,单位为像素,返回值为整型。

语法:

int imagesx( resource image )
Copy after login

参数

  • image 为如 imagecreatetruecolor()、imagecreatefromjpeg() 等函数返回的图像资源。

PHP 获取图像高度函数:imagesy()

imagesy() 函数用于获取图像的高度,语法及用法同 imagesx() 。

语法:

int imagesy( resource image )
Copy after login

参数

  • image 为如 imagecreatetruecolor()、imagecreatefromjpeg() 等函数返回的图像资源。

实例

<?php
header("Content-Type: text/html; charset=utf-8");
$img = imagecreatefrompng("logo.png");
echo "图像宽度:",imagesx( $img ),"<br />";
echo "图像高度:",imagesy( $img );
?>
Copy after login

浏览器输出:

图像宽度:160
图像高度:76
Copy after login

更多相关知识,请访问 PHP中文网!!

Related labels:
php
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template