Skip to content

Commit eafa6bb

Browse files
committed
fix with 1.0.4 extension
turns out you can't catch{} undefined functions
1 parent da6b151 commit eafa6bb

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/Image.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ class Image extends ImageAutodoc implements \ArrayAccess
433433
*
434434
* @internal
435435
*/
436-
private $nicknameToCanonical = [
436+
private static $nicknameToCanonical = [
437437
"csvload" => "VipsForeignLoadCsv",
438438
"matrixload" => "VipsForeignLoadMatrix",
439439
"rawload" => "VipsForeignLoadRaw",
@@ -724,19 +724,19 @@ public static function newFromFile(
724724
*/
725725
public static function findLoad(string $filename): string
726726
{
727-
$result = null;
728-
729-
try {
730-
# added in php-vips-ext 1.0.5
727+
# added in 1.0.5 of the binary module
728+
if (version_compare(phpversion("vips"), "1.0.5") >= 0) {
731729
$result = vips_foreign_find_load($filename);
732-
} catch (Exception $e) {
730+
} else {
731+
$result = null;
732+
733733
# fallback: use the vips-loader property ... this can be much slower
734734
try {
735-
$image = newFromFile($filename);
735+
$image = Image::newFromFile($filename);
736736
# Unfortunately, vips-loader is the operation nickname, rather
737737
# than the canonical name returned by vips_foreign_find_load().
738738
$loader = $image->get("vips-loader");
739-
$result = $nicknameToCanonical[$loader];
739+
$result = Image::$nicknameToCanonical[$loader];
740740
} catch (Exception $e) {
741741
}
742742
}
@@ -776,20 +776,20 @@ public static function newFromBuffer(
776776
*/
777777
public static function findLoadBuffer(string $buffer): string
778778
{
779-
$result = null;
779+
# added in 1.0.5 of the binary module
780+
if (version_compare(phpversion("vips"), "1.0.5") >= 0) {
781+
$result = vips_foreign_find_load($filename);
782+
} else {
783+
$result = null;
780784

781-
try {
782-
# added in php-vips-ext 1.0.5
783-
$result = vips_foreign_find_load_buffer($buffer);
784-
} catch (Exception $e) {
785785
# fallback: use the vips-loader property ... this can be much slower
786786
try {
787-
$image = newFromBuffer($buffer);
787+
$image = Image::newFromBuffer($buffer);
788788
# Unfortunately, vips-loader is the operation nickname, rather
789789
# than the canonical name returned by
790790
# vips_foreign_find_load_buffer().
791791
$loader = $image->get("vips-loader");
792-
$result = $nicknameToCanonical[$loader];
792+
$result = Image::$nicknameToCanonical[$loader];
793793
} catch (Exception $e) {
794794
}
795795
}

0 commit comments

Comments
 (0)