diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3bd065217..da3fe6d27 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -36,7 +36,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-version }} - extensions: ctype, dom, fileinfo, gd, iconv, intl, libxml, mbstring, simplexml, xml, xmlreader, xmlwriter, zip, zlib + extensions: ctype, dom, fileinfo, filter, gd, iconv, intl, libxml, mbstring, simplexml, xml, xmlreader, xmlwriter, zip, zlib coverage: none - name: Get composer cache directory @@ -83,7 +83,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: 8.4 - extensions: ctype, dom, fileinfo, gd, iconv, intl, libxml, mbstring, simplexml, xml, xmlreader, xmlwriter, zip, zlib + extensions: ctype, dom, fileinfo, filter, gd, iconv, intl, libxml, mbstring, simplexml, xml, xmlreader, xmlwriter, zip, zlib coverage: none # This is non-ideal because it only checks for the last commit of the PR, not all of them, but better than nothing @@ -100,7 +100,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: 8.4 - extensions: ctype, dom, fileinfo, gd, iconv, intl, libxml, mbstring, simplexml, xml, xmlreader, xmlwriter, zip, zlib + extensions: ctype, dom, fileinfo, filter, gd, iconv, intl, libxml, mbstring, simplexml, xml, xmlreader, xmlwriter, zip, zlib coverage: none tools: cs2pr @@ -131,7 +131,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: 8.4 - extensions: ctype, dom, fileinfo, gd, iconv, intl, libxml, mbstring, simplexml, xml, xmlreader, xmlwriter, zip, zlib + extensions: ctype, dom, fileinfo, filter, gd, iconv, intl, libxml, mbstring, simplexml, xml, xmlreader, xmlwriter, zip, zlib coverage: none tools: cs2pr @@ -162,7 +162,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: 8.4 - extensions: ctype, dom, fileinfo, gd, iconv, intl, libxml, mbstring, simplexml, xml, xmlreader, xmlwriter, zip, zlib + extensions: ctype, dom, fileinfo, filter, gd, iconv, intl, libxml, mbstring, simplexml, xml, xmlreader, xmlwriter, zip, zlib coverage: none tools: cs2pr @@ -193,7 +193,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: 8.4 - extensions: ctype, dom, fileinfo, gd, iconv, intl, libxml, mbstring, simplexml, xml, xmlreader, xmlwriter, zip, zlib + extensions: ctype, dom, fileinfo, filter, gd, iconv, intl, libxml, mbstring, simplexml, xml, xmlreader, xmlwriter, zip, zlib coverage: none tools: cs2pr @@ -232,7 +232,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: 8.4 - extensions: ctype, dom, fileinfo, gd, iconv, intl, libxml, mbstring, simplexml, xml, xmlreader, xmlwriter, zip, zlib + extensions: ctype, dom, fileinfo, filter, gd, iconv, intl, libxml, mbstring, simplexml, xml, xmlreader, xmlwriter, zip, zlib coverage: pcov - name: Get composer cache directory diff --git a/composer.json b/composer.json index 62949ec4e..775763f58 100644 --- a/composer.json +++ b/composer.json @@ -73,6 +73,7 @@ "ext-ctype": "*", "ext-dom": "*", "ext-fileinfo": "*", + "ext-filter": "*", "ext-gd": "*", "ext-iconv": "*", "ext-libxml": "*", diff --git a/composer.lock b/composer.lock index 64c1aec0d..e6bd57214 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c0bec0237e58e450d1e2861f8141e823", + "content-hash": "95ca24faf04b29c2e5fdc99d49f040d7", "packages": [ { "name": "composer/pcre", @@ -5675,6 +5675,7 @@ "ext-ctype": "*", "ext-dom": "*", "ext-fileinfo": "*", + "ext-filter": "*", "ext-gd": "*", "ext-iconv": "*", "ext-libxml": "*", diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php index fc1f72c42..f710f5103 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php @@ -3,7 +3,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; use Composer\Pcre\Preg; -use Datetime; +use DateTime; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; @@ -45,12 +45,12 @@ class TimeValue * Date information in time_text is ignored. * Or can be an array of date/time values * - * @return array|Datetime|float|int|string Excel date/time serial value, PHP date/time serial value or PHP date/time object, + * @return array|DateTime|float|int|string Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag * If an array of numbers is passed as the argument, then the returned result will also be an array * with the same dimensions */ - public static function fromString(null|array|string|int|bool|float $timeValue): array|string|Datetime|int|float + public static function fromString(null|array|string|int|bool|float $timeValue): array|string|DateTime|int|float { if (is_array($timeValue)) { return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $timeValue); @@ -88,7 +88,7 @@ class TimeValue } elseif ($retType === Functions::RETURNDATE_UNIX_TIMESTAMP) { $retValue = (int) SharedDateHelper::excelToTimestamp($excelDateValue + 25569) - 3600; } else { - $retValue = new Datetime('1900-01-01 ' . $PHPDateArray['hour'] . ':' . $PHPDateArray['minute'] . ':' . $PHPDateArray['second']); + $retValue = new DateTime('1900-01-01 ' . $PHPDateArray['hour'] . ':' . $PHPDateArray['minute'] . ':' . $PHPDateArray['second']); } } diff --git a/src/PhpSpreadsheet/Worksheet/MemoryDrawing.php b/src/PhpSpreadsheet/Worksheet/MemoryDrawing.php index dfef51ded..f036f9885 100644 --- a/src/PhpSpreadsheet/Worksheet/MemoryDrawing.php +++ b/src/PhpSpreadsheet/Worksheet/MemoryDrawing.php @@ -176,13 +176,6 @@ class MemoryDrawing extends BaseDrawing $temporaryFileName = File::temporaryFilename(); file_put_contents($temporaryFileName, $imageString); - $mimeType = self::identifyMimeTypeUsingExif($temporaryFileName); - if ($mimeType !== null) { - unlink($temporaryFileName); - - return $mimeType; - } - $mimeType = self::identifyMimeTypeUsingGd($temporaryFileName); if ($mimeType !== null) { unlink($temporaryFileName); @@ -195,21 +188,12 @@ class MemoryDrawing extends BaseDrawing return self::MIMETYPE_DEFAULT; } - private static function identifyMimeTypeUsingExif(string $temporaryFileName): ?string - { - if (function_exists('exif_imagetype')) { - $imageType = @exif_imagetype($temporaryFileName); - $mimeType = ($imageType) ? image_type_to_mime_type($imageType) : null; - - return self::supportedMimeTypes($mimeType); - } - - return null; - } + /** @internal */ + protected static string $getImageSize = 'getImageSize'; private static function identifyMimeTypeUsingGd(string $temporaryFileName): ?string { - if (function_exists('getimagesize')) { + if (function_exists(static::$getImageSize)) { $imageSize = @getimagesize($temporaryFileName); if (is_array($imageSize)) { $mimeType = $imageSize['mime']; diff --git a/tests/PhpSpreadsheetTests/Worksheet/MemoryDrawing2.php b/tests/PhpSpreadsheetTests/Worksheet/MemoryDrawing2.php new file mode 100644 index 000000000..9df81390c --- /dev/null +++ b/tests/PhpSpreadsheetTests/Worksheet/MemoryDrawing2.php @@ -0,0 +1,12 @@ +getMimeType()); self::assertSame(MemoryDrawing::RENDERING_JPEG, $drawing->getRenderingFunction()); } + + public function testMemoryDrawingFromStreamNoGetImageSize(): void + { + $imageFile = __DIR__ . '/../../data/Worksheet/officelogo.jpg'; + + $imageStream = fopen($imageFile, 'rb'); + if ($imageStream === false) { + self::markTestSkipped('Unable to read Image file for MemoryDrawing'); + } + $drawing = MemoryDrawing2::fromStream($imageStream); + fclose($imageStream); + + self::assertIsObject($drawing->getImageResource()); + + self::assertSame(MemoryDrawing::MIMETYPE_DEFAULT, $drawing->getMimeType()); + self::assertSame(MemoryDrawing::RENDERING_DEFAULT, $drawing->getRenderingFunction()); + } }