1

When I use either resizeImage or sampleImage, I get errors indicating I'm not supplying enough parameters, like so...

Warning: Imagick::sampleimage() expects exactly 2 parameters, 1 given

In fact, I am only supplying the first parameter because I want to set the width, and not the height, to preserve the aspect ratio...

$subImage->resizeImage($w);

The code works, and I believe all parameters should be optional except the first one, so why is there an error and how do I eliminate it?

arnoldbird
  • 886
  • 1
  • 13
  • 30

1 Answers1

1

For Imagick::sampleImage you would need to calculate the finial height.

 // new height = original height / original width * new width
 $h = $subImage->getImageHeight() / $subImage->getImageWidth() * $w
 $subImage->sampleimage($w, $h);

I believe all parameters should be optional

Remember the Imagick library binds ImageMagick's C-API, and some of the inherited porcelain of CLI-API does not carry over directly. Your application must do the additional calculations, or you'll experience undefined behavior. Handling aspect rations, quantum colors, degrees, and percentage values are good examples of what your responsible for.

Community
  • 1
  • 1
emcconville
  • 23,800
  • 4
  • 50
  • 66