问题标签 [getimagesize]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
1572 浏览

php - PHP - getimagesize 函数

getimagesize使用额外的 HTTP 请求还是可以远程找出大小?

注意:图像是外部的

0 投票
8 回答
19874 浏览

php - PHP getimagesize() 返回什么类型的文件?

有谁知道 PHP 的 getimagesize() 函数返回的第三个值的所有可能结果?示例下面的代码将返回:

  • $imageinfo['2'] = 2;对于jpg图像,
  • $imageinfo['2'] = 3;对于png图像,
  • $imageinfo['2'] = 0;gif图像。

上面的数字可能不正确,但你明白了。

我在 php.net 或其他任何地方都找不到第三个值的所有可能结果的列表。

0 投票
5 回答
40279 浏览

php - getimagesize 找不到文件时处理错误

当我尝试getimagesize($img)并且图像不存在时,出现错误。我不想先检查文件是否存在,只处理错误。

我不确定如何try catch工作,但我想做类似的事情:

0 投票
5 回答
18381 浏览

php - getimagesize() 在某些图像上返回 false

我正在运行getimagesize()以确定上传的文件是否为有效图像以及它是否为 MIME 类型。我的 web 应用程序的用户报告说,他的一些图像在上传后出现“无效文件类型”错误。所以我让他寄给我一些检查。

错误字符串本身没有意义,因为它只是我在函数失败时编写的通用文本(返回FALSE)。我尝试增加 PHP 的内存限制但没有成功。此外,日志不会显示任何异常。文件有问题还是有其他问题?有没有更好的方法来做这个操作?

我接受任何接受的文件getimagesize()(意味着它具有宽度/高度),我只是检查它是否不会返回FALSE(尽管我的实际范围是 jpg|jpeg|png|gif|bmp|tif|tiff) . 服务器正在运行 PHP/5.2.6-1+lenny3。我再说一遍,这只发生在链接的图像和同一系列的其他图像中,所以我更倾向于认为它与 Lizard 的暗示有关。

$_FILES在到达之前似乎是空的,getimagesize($_FILES['Filedata']['tmp_name'])因此从未真正检查过该文件。我必须弄清楚为什么这些文件没有像其他文件一样提交(也许对 PHP 来说太大了?有什么想法吗?)。

0 投票
3 回答
4302 浏览

php - 无法获取图像文件扩展名

我正在使用 Uploadify 将图像上传到服务器。
图像已上传,并放置在 Web 服务器的临时文件夹中。

现在我需要处理文件,然后将其移动到它的真实位置,并且我有以下代码:

我没有使用正则表达式来读取文件名,因为用户可以为文件命名任何东西,所以我必须读取文件数据。

有任何建议吗?

0 投票
1 回答
5911 浏览

javascript - 在图像上使用 max-width = 100% 和 max-height = 100%,计算显示宽度/高度

我正在为各种尺寸的图像创建幻灯片,以在画布区域内垂直和水平居中显示。

在我的 CSS 中,我将图像的宽度和高度设置为 100%,以便每个图像按比例填充画布。我希望画布自动调整大小以适应查看者的屏幕尺寸,因为图像的原始尺寸非常大(高达 800 像素)。

我正在使用 jQuery 1.4,并使用图像的高度来计算将其绝对定位到画布中间的最高值。

我曾尝试使用 jQuery 来获取 .height()、innerHeight() 和 outerHeight(),但它总是获得图像的完整大小。

我从 jQuery 对象中提取 DOM 元素并尝试使用 .width、.offsetWidth 和 .clientWidth,但这似乎总是返回图像的完整大小。

Firebug 显示正确的尺寸,所以我知道有一些方法可以计算图像的实际显示高度,我只是不知道它是什么。如果设置 max-height = 100%,如何获得图像的实际显示高度?

我不想在 js 中计算和设置每个图像的高度,但如果必须,我会的。看起来我应该能够设置画布大小并自动调整图像。

0 投票
1 回答
845 浏览

php - PHP getimagesize在字符串中带有&符号会产生错误

我在 PHP 中使用 getimagesize 函数,路径字符串包含一个 & 符号,否则很好。该页面给了我调用 getimagesize() 的错误。但是,查看源代码时,我看到与号作为 & 而不仅仅是 & 我认为这会导致错误,因为 PHP 不需要将其转换为 html 标记来查找路径,对吧?

这是错误:

警告:getimagesize(image.php?name=username&pic=picture) [function.getimagesize]:打开流失败:没有这样的文件或目录

0 投票
1 回答
1923 浏览

php - getimagesize() 的 PHP 问题

我在 PHP 中使用 getimagesize() 函数,它不断返回错误:

getimagesize(image.php?name=username&pic=picture) [function.getimagesize]:打开流失败:没有这样的文件或目录

我没有用它做任何奇怪的事情。我能想象的唯一问题是路径 URL 是另一个 PHP 脚本,它返回一个带有图像标题的页面,并且该 URL 中有一个 & 符号。

这是我的代码:

0 投票
1 回答
673 浏览

silverlight - 如何在 Silverlight 中获取图像的高度?

我在Silverlight中有这段代码:

现在我想找出图像的高度

  • WPF中,我可以使用image.Source.Height获得它,但这在 Silverlight 中不可用
  • bitmapImage.Height也不存在
  • 当我调试和检查图像对象时,我最终得到了具有准确高度的PixelHeight,但我似乎无法访问它
  • 我找到image.ActualHeight但它是 0。

如何获得图像的高度?

0 投票
3 回答
2660 浏览

php - Automatically adding width and height attributes to tags with a PHP function

What I want is a function I can run on user input that will intelligently find and add the width and height attributes to any <img> tag in a blob of HTML so as to avoid page-reflowing issues while images load.

I am writing the posting script for a PHP forum, where a user's input is sanitised and generally made nicer before writing it to the database for later display. As an example of what I do to make things nicer, I have a script that inserts alt attributes into images like so:

Here are two images: <img src="http://example.com/image.png"> <img src="http://example.com/image2.png">

which, upon sanitising by the posting script, becomes

Here are two images: <img src="http://example.com/image.png" alt="Posted image"> <img src="http://example.com/image2.png" alt="Posted image">

(This makes it validate under HTML 4 strict, but maybe isn't in the spirit of the alt attribute—alas!)

So, for my function, I have a vague idea that the server will need to run getimagesize() on each external image it finds in the block of HTML, then apply the attributes that function generates to each and every <img> tag it runs into. I assume that this function has been written before, but I have had no luck on Google or php.net docs. Do I have to start from scratch, or is somebody aware of a (relatively) robust function that I can use or adapt to do this job?