Skip to content

Commit

Permalink
Added 2nd optional parameter to Image::convertToAlternative to prov…
Browse files Browse the repository at this point in the history
…ide your own options for loading the image as tiff.
  • Loading branch information
chregu committed Dec 6, 2017
1 parent 1a21bed commit 9036993
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

### 0.1.0 (2017-12-06)

* Added 2nd optional parameter to `Image::convertToAlternative` to provide your own options for loading the image as tiff.

### 0.0.5 (2017-12-03)

* ext/vips 1.0.8 is required. Throw exceptions in methods, which needs vips 8.6.
Expand Down
16 changes: 10 additions & 6 deletions lib/Imagine/Vips/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -702,11 +702,12 @@ public static function getColorArrayAlpha(ColorInterface $color, $bands = 4): ar
}

/**
* @param ImagineInterface|null $imagine the alternative imagine interface to use, autodetects, if not set
* @param ImagineInterface|null $imagine the alternative imagine interface to use, autodetects, if not set
* @param array|null $tiffOptions options to load the tiff image for conversion, eg ['strip' => true]
*
* @return ImageInterface
*/
public function convertToAlternative(ImagineInterface $imagine = null)
public function convertToAlternative(ImagineInterface $imagine = null, array $tiffOptions = [])
{
if (null === $imagine) {
if (class_exists('Imagick')) {
Expand All @@ -716,7 +717,7 @@ public function convertToAlternative(ImagineInterface $imagine = null)
}
}

return $imagine->load($this->getImageStringForLoad($this->vips));
return $imagine->load($this->getImageStringForLoad($this->vips, $tiffOptions));
}

protected function applyProfile(ProfileInterface $profile, VipsImage $vips)
Expand Down Expand Up @@ -784,13 +785,16 @@ protected function getDefaultProfileForInterpretation($vips)
}

/**
* @param VipsImage $res
* @param VipsImage $res
* @param array|null $tiffOptions options to load the tiff image for conversion, eg ['strip' => true]
*
* @return string
*/
protected function getImageStringForLoad(VipsImage $res)
protected function getImageStringForLoad(VipsImage $res, $tiffOptions = [])
{
return $res->tiffsave_buffer(['compression' => ForeignTiffCompression::NONE]);
$options = array_merge(['compression' => ForeignTiffCompression::NONE], $tiffOptions);

return $res->tiffsave_buffer($options);
}

/**
Expand Down

0 comments on commit 9036993

Please sign in to comment.