silverstripe / silverstripe-assets

Silverstripe Assets component
BSD 3-Clause "New" or "Revised" License
9 stars 65 forks source link

`File::getIsImage()` always returns `false`, even if the file is an image. #594

Open GuySartorelli opened 4 months ago

GuySartorelli commented 4 months ago

Module version(s) affected

4.*, 5.*

Description

If you create a new file, and the file is an image, and you call $file->getIsImage(), it returns false if you created it using the File class.

How to reproduce

Execute the below code, where $someFileLocation is the path to a file on your filesystem.

Regardless of what type of file that is, whether it's an image or not, false will be dumped out.

use SilverStripe\Assets\File;

$file = File::create();
$file->setFromLocalFile($someFileLocation);
$file->write();

// Publish the file
$file->publishFile();

var_dump($file->getIsImage());

Possible Solution

Check $this->appCategory(), e.g:

public function getIsImage()
{
    return in_array($this->appCategory(), ['image', 'image/supported']);
}

That won't capture images that developers put in custom app categories - but I think that's an edge case we can live with.

Additional Context

No response

Validations