Git Product home page Git Product logo

fast-image-size's People

Contributors

danielhanold avatar joshyphp avatar marc1706 avatar pierreuh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fast-image-size's Issues

No valid size info on larger TIFF files

Larger TIFF files can have the size info further back than currently expected header size. As a result of that, no valid size info is found and this PHP debug warning is generated:

[phpBB Debug] PHP Warning: in file [ROOT]/vendor/marc1706/fast-image-size/lib/Type/TypeTif.php on line 80: unpack(): Type v: not enough input, need 2, have 0

Memory leak with PHP 8.1

It appears that the loaded images remain in memory even when the FastImageSize object is unset.

PHP 8.1.13
Zend Engine v4.1.13
Zend OPcache v8.1.13

Loaded extensions:

zend_extension=opcache.so
extension=pdo.so
extension=pdo_pgsql.so
extension=pgsql.so
extension=xml.so
extension=calendar.so
extension=ctype.so
extension=curl.so
extension=dom.so
extension=exif.so
extension=ffi.so
extension=fileinfo.so
extension=ftp.so
extension=gd.so
extension=gettext.so
extension=iconv.so
extension=imagick.so
extension=intl.so
extension=mbstring.so
extension=phar.so
extension=posix.so
extension=readline.so
extension=shmop.so
extension=simplexml.so
extension=sockets.so
extension=sysvmsg.so
extension=sysvsem.so
extension=sysvshm.so
extension=tokenizer.so
extension=xmlreader.so
extension=xmlwriter.so
extension=xsl.so
extension=zip.so

Code example that demonstrates the leak:

for ($i = 0; $i < ENOUGH_TO_EXCEED_RAM_LIMIT; $i++) {
  $mem = memory_get_usage();
  $FastImageSize = new \FastImageSize\FastImageSize();
  $path = "path/to/image.jpg";
  $imageSize = $FastImageSize->getImageSize($filePath);
  unset($FastImageSize);
  unset($imageSize);
  echo "leak: " . memory_get_usage() - $mem . " bytes<br>";
}

This code terminates with the following fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 790528 bytes) in /var/www/vendor/marc1706/fast-image-size/lib/FastImageSize.php on line 189

Cannot parse images on localhost

I'm running into issues parsing image data when it's on localhost.

$FastImageSize = new \FastImageSize\FastImageSize();
$imageSize = $FastImageSize->getImageSize('http://0.0.0.0:8000/files/1461.png');
echo $imageSize;

The image can be loaded in the browser via that path, but for some reason it can't be found by fast-image-size.

Hidden dependency of mbstring not needed

This package has a hidden dependency that is actually not needed.

mbstring functions are used but seems to be not needed at all.

They occured only at this line.

$className = '\FastImageSize\Type\Type' . mb_convert_case(mb_strtolower($imageType), MB_CASE_TITLE);

Replacing this line by something like this would remove dependency to mbstring
$className = '\FastImageSize\Type\Type' . ucfirst($imageType);

Since the content of $imageType is defined from class parameter, there should be no need to rely on mbstring functions.

Either that or update composer.json to require ext-mbstring module, so that at least mbstring dependency is not hidden.

Library seems to be failing on some files

Using the library as part of phpBB 3.2 on PHP 5.6.
One of the users complained that their files could not be uploaded.
I investigated the issue and found that FastImage Size apparently fails to get image size for their photos.
Interestingly, the core PHP function, getimagesize(), works fine with these files.

Links to files:
http://filedistr.ru/2018/IMG_20180720_103159.jpg
http://filedistr.ru/2018/IMG_20180724_181130.jpg

I fixed the issue on my site by adding the following lines to function TypeJpeg::getSize()

After:

		// Look through file for SOF marker
		$size = $this->getSizeInfo();

Added:

                if (empty($size)) {
                    $info = getimagesize($filename);
                    if (!empty($info) && is_array($info)) {
                        $size = array(
                            'width' => $info[0],
                            'height' => $info[1],
                        );
                        
                    }
                }

This is not necessarily the best way to fix it, this is just so that you have an idea.

Can't find dimensions for TIFF files

I'm using FastImageSize in phpBB 3.2.0 !

When uploading TIFF images in a post I get an error for failing to get the dimensions of the file. However when I change the TIF_HEADER_SIZE number e.g. to 512000 (in lib\Type\TypeTif.php) then it works.

getImageSize() uses file extension over the type

When you pass a known file type to the method, it uses the file extension instead of the type passed as the parameter.
This is a problem with uploaded files in windows, because when they are uploaded, they have the extension .tmp, and the method uses this extension as type.

[phpBB Debug] FastImageSize Failed to open stream

Error is reported @ phpBB: https://tracker.phpbb.com/browse/PHPBB3-16742
But someone told me to report it here...

I'm receiving this error in a topic with an attachment.
It's strange, because it's only that 1 topic that gives this error...
All others with attachments are fine...

[phpBB Debug] PHP Warning: in file [ROOT]/vendor/marc1706/fast-image-size/lib/FastImageSize.php on line 189: file_get_contents(https://www.phpbbnl.be/download/file.php?id=15&amp;mode=view): Failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden [phpBB Debug] PHP Warning: in file [ROOT]/vendor/marc1706/fast-image-size/lib/FastImageSize.php on line 189: file_get_contents(https://www.phpbbnl.be/download/file.php?id=16&amp;mode=view): Failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden

You can see the error here: https://www.phpbbnl.be/viewtopic.php?f=5&t=8

I use PHP 8.0.3
The error is gone with PHP 7.4

=====

PHP: 8.0.3 - FPM Served By nginx
MySQL(i) 10.5.9-MariaDB
Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz (6 core(s))
CentOS Linux 7.9.2009 (Core)
Plesk Obsidian v18.0.34

Problem using url filename with space not encoded

If we have an url image name with space not encoded, for es.
$FastImageSize->getImageSize('https://example.com/some random image.jpg');
the function will not work because the file_get_contents do not accept url not encoded.
As a fix, I propose to automatically encode the filename in the getImage function.
$filename = urldecode($filename);
$filename = dirname($filename) . '/'. rawurlencode(basename($filename));
$this->data = @file_get_contents($filename, null, null, $offset, $length);

Do not rely on EXIF IFD image size

The EXIF IFD image size is unfortunately not a reliable source of the image size. Therefore, it should be replaced by a solid way of handling both images with and without exif data.

Retrieve image size info from EXIF IFD if possible

Some images saved with newer versions of Photoshop no longer carry the JFIF data but only the EXIF data including EXIF IFD. As a result of that, image size info needs to be extracted from EXIF instead of the JFIF header.

Jpeg format not working

I have some jpeg images not working with library.One of the images I'm using is attached to the issue.

The issue seems to be :
$this->data = $this->fastImageSize->getImage($filename, 0, self::JPEG_MAX_HEADER_SIZE, false);

on file
https://github.com/marc1706/fast-image-size/blame/master/lib/Type/TypeJpeg.php

it returns an empty object even if the image is a jpeg.

I already tried to change extension of file from "jpg" to "jpeg". I tried aslo to expand max header size, but with no results.

xlarge_img_20150602_134657

Support WebP images

The WebP seems to become a good alternative to JPEG or PNG, so even though not all browsers support it yet there are some sites out there that can already send them to the browser (mostly by looking at the Accept-Header).

I assume that the support is going to grow more and more so maybe you can add support for it?

An error occurs while type class are generating.

At this line https://github.com/marc1706/fast-image-size/blob/master/lib/FastImageSize.php#L81 ucfirst function is used to generate class name. ico, iff word cant be converted correcly by ucfirst, and it cause a class not found error. They are converted to ico, iff (as same name).
mb_convert_case function works fine.
May be we should use like this.
mb_convert_case($str, MB_CASE_TITLE, "UTF-8");

I am going to send a PR. Do you have any comment for this issue.

https://github.com/Lullabot/amp-library package uses your package. 3-5 monts ago, it used to work without any problem.

Thanks.

Filename casing issues

In this directory: https://github.com/marc1706/fast-image-size/tree/bafc33cc5315e5636674d3639bda98a07d33e7b9/tests/fixture

There are files JPG and PNG as well as jpg and png. This is an issue for case-insensitive systems like Windows and OS X/macOS (by default). I noticed when when using unison to sync files between a VM and a host machine. Unison kept reporting skipped files:

  skipped: vendor/marc1706/fast-image-size/tests/fixture/jpg (Two or more files on a case-sensitive system have names identical except for case.  They cannot be synchronized to a case-insensitive file system.  (File 'vendor/marc1706/fast-image-size/tests/fixture/jpg'))
  skipped: vendor/marc1706/fast-image-size/tests/fixture/png (Two or more files on a case-sensitive system have names identical except for case.  They cannot be synchronized to a case-insensitive file system.  (File 'vendor/marc1706/fast-image-size/tests/fixture/png'))

In checking my host machine files, I noticed that I didn't have any files jpg or png at all. On the VM, where the repo was initially checked out/installed by composer, I see jpg and JPG. The VM is case-sensitive, so it works fine. The host machine is not.

Is there a way you can change this so that you don't have file name conflicts on case-insensitive file systems?

Error to get image size

I get this error:
PHP Notice: Uninitialized string offset: 25214 in ....lib/Type/TypeJpeg.php on line 128

I use this code:
$FastImageSize = new \FastImageSize\FastImageSize();
$imageSize = $FastImageSize->getImageSize('http://www.techspot.com/articles-info/1121/images/P34WS-12.jpg');
print_r($imageSize);

The same error you can get with these images:
http://www.techspot.com/articles-info/1121/images/P34WS-4.jpg
http://www.techspot.com/articles-info/1121/images/P34WS-17.jpg

Library fails if the URL of image is redirected (i.e. http to https)

Could it be, that the function @file_get_contents has a problem with some redirected links?

That's a problem in phpBB, if a link to an image is redirected from http to https. The server answers with a 301 or 302, i.e. permanently redirected and after this the image data are transfered.

In this example https://www.stummiforum.de/viewtopic.php?f=14&t=161634&start=25#p1899025 the image link is redirected to https if you call it with http. This server strangely answers first with "Please enable Javascript".

The result of @file_get_contents are the first answer of the server, which isn't the image. So the library tries to find a image size in this data which results in an error:

"It was not possible to determine the dimensions of the image. Please verify that the URL you entered is correct."

I think, there is a javascript for redirect and @file_get_contents get this script result and not an image.

Can this problem be confirmed?

Image size issue for images with wrong extension.

Hello.
I've faced an issue when image size can't be obtained for images with wrong extension (for example jpeg image format with PNG extension). Yes, I know it is not normal to have image with wrong extension, but sometimes it happens.

I found this issue parsing "Lullabot\AMP" issue (laravel). It doesn't convert "img" tag to "amp-img" when image size is undefined. So I have a solution, but I think there could be better one.

So my simple solution is for class "FastImageSize", function "getImageSize" you can add this to end of else statement:

if(!(sizeof($this->size) > 1)) { $this->data = ''; $this->getImagesizeUnknownType($file); }

Thanks.

Capitalized filename extensions e.g. 'JPG' vs 'jpg'

I ran into a circumstance where a file URL had an all caps file extension i.e. '.JPG' instead of expected '.jpg', but the regex in FastImageSize::getImageSize() only matches lower-case. I propose matching upper-case letters as well, then passing the resulting matched extension through 'strtolower()' before sending to FastImageSize::getImageSizeByExtension().

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.