selective-php / image-type

Image type (format) detection for PHP
MIT License
7 stars 4 forks source link

Travis CI build is failed due to PSB detection #62

Closed peter279k closed 5 years ago

peter279k commented 5 years ago

As title, the PSB detection is failed, and I tihnk we should enhance PsdDetector class.

<?php

namespace Selective\ImageType\Detector;

use Selective\ImageType\ImageType;
use SplFileObject;

/**
 * Detector.
 */
final class PsbDetector implements DetectorInterface
{
    /**
     * PSB (Photoshop Large Document) identification.
     *
     * @param SplFileObject $file The image file
     *
     * @return ImageType|null The image type
     */
    public function detect(SplFileObject $file): ?ImageType
    {
        return $file->fread(5) === "8BPS\0\2" ? new ImageType(ImageType::PSB) : null;
    }
}
<?php

namespace Selective\ImageType\Detector;

use Selective\ImageType\ImageType;
use SplFileObject;

/**
 * Detector.
 */
final class PsdDetector implements DetectorInterface
{
    /**
     * PSD identification.
     *
     * @param SplFileObject $file The image file
     *
     * @return ImageType|null The image type
     */
    public function detect(SplFileObject $file): ?ImageType
    {
        return $file->fread(2) === '8B' ? new ImageType(ImageType::PSD) : null;
    }
}
peter279k commented 5 years ago

It looks like the psd and psb identification detection is different.

peter279k commented 5 years ago

References

odan commented 5 years ago

It should be fixed now. Thanks.