Skip to content

Commit 9951cab

Browse files
authored
Merge pull request #63 from jcupitt/vips-8.6
Fix blendmode + add missing @throws declarations
2 parents f016fd5 + 408586a commit 9951cab

File tree

3 files changed

+48
-6
lines changed

3 files changed

+48
-6
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ php:
1111
env:
1212
global:
1313
- VIPS_VERSION_MAJOR=8
14-
- VIPS_VERSION_MINOR=5
15-
- VIPS_VERSION_MICRO=8
14+
- VIPS_VERSION_MINOR=6
15+
- VIPS_VERSION_MICRO=0
1616
- PATH=$HOME/vips/bin:$PATH
1717
- LD_LIBRARY_PATH=$HOME/vips/lib:$LD_LIBRARY_PATH
1818
- PKG_CONFIG_PATH=$HOME/vips/lib/pkgconfig:$PKG_CONFIG_PATH

src/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public static function concurrencySet($value)
146146
*
147147
* @return string
148148
*/
149-
public static function version()
149+
public static function version(): string
150150
{
151151
return vips_version();
152152
}

src/Image.php

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,43 @@ class Image extends ImageAutodoc implements \ArrayAccess
537537
'openexrload' => 'VipsForeignLoadOpenexr'
538538
];
539539

540+
/**
541+
* Combine takes an array of blend modes, passed to libvips as an array of
542+
* int. Because libvips does now know they should be enums, we have to do
543+
* the string->int conversion ourselves. We ought to introspect to find the
544+
* mapping, but until we have the machinery for that, we just hardwire the
545+
* mapping here.
546+
*
547+
* @internal
548+
*/
549+
private static $blendModeToInt = [
550+
BlendMode::CLEAR => 0,
551+
BlendMode::SOURCE => 1,
552+
BlendMode::OVER => 2,
553+
BlendMode::IN => 3,
554+
BlendMode::OUT => 4,
555+
BlendMode::ATOP => 5,
556+
BlendMode::DEST => 6,
557+
BlendMode::DEST_OVER => 7,
558+
BlendMode::DEST_IN => 8,
559+
BlendMode::DEST_OUT => 9,
560+
BlendMode::DEST_ATOP => 10,
561+
BlendMode::XOR => 11,
562+
BlendMode::ADD => 12,
563+
BlendMode::SATURATE => 13,
564+
BlendMode::MULTIPLY => 14,
565+
BlendMode::SCREEN => 15,
566+
BlendMode::OVERLAY => 16,
567+
BlendMode::DARKEN => 17,
568+
BlendMode::LIGHTEN => 18,
569+
BlendMode::COLOUR_DODGE => 19,
570+
BlendMode::COLOUR_BURN => 20,
571+
BlendMode::HARD_LIGHT => 21,
572+
BlendMode::SOFT_LIGHT => 22,
573+
BlendMode::DIFFERENCE => 23,
574+
BlendMode::EXCLUSION => 24
575+
];
576+
540577
/**
541578
* The resource for the underlying VipsImage.
542579
*
@@ -1013,6 +1050,8 @@ public static function newInterpolator(string $name)
10131050
*
10141051
* @param mixed $value The value to set each pixel to.
10151052
*
1053+
* @throws Exception
1054+
*
10161055
* @return Image A new Image.
10171056
*/
10181057
public function newFromImage($value): Image
@@ -1483,6 +1522,7 @@ public function offsetGet($offset): Image
14831522
* @param Image $value The band to insert
14841523
*
14851524
* @throws \BadMethodCallException if the offset is not integer or null
1525+
* @throws Exception
14861526
*
14871527
* @return void
14881528
*/
@@ -1528,6 +1568,7 @@ public function offsetSet($offset, $value)
15281568
*
15291569
* @throws \BadMethodCallException if there is only one band left in
15301570
* the image
1571+
* @throws Exception
15311572
*
15321573
* @return void
15331574
*/
@@ -1976,9 +2017,10 @@ public function composite($other, $mode, array $options = []): Image
19762017
$mode = [$mode];
19772018
}
19782019

1979-
foreach ($mode as &$x) {
1980-
$x = BlendMode::TO_INT[$x];
1981-
}
2020+
$mode = array_map(function ($x) {
2021+
// Use BlendMode::OVER if a non-existent value is given.
2022+
return self::$blendModeToInt[$x] ?? BlendMode::OVER;
2023+
}, $mode);
19822024

19832025
return self::call(
19842026
'composite',

0 commit comments

Comments
 (0)