claviska / SimpleImage

A PHP class that makes working with images and GD as simple as possible.
MIT License
1.38k stars 382 forks source link

Implicit conversion from float 50.800000000000004 to int loses precision #307

Closed a-d-w-s closed 1 year ago

a-d-w-s commented 1 year ago

If I connect two images, I get an error message: notice: Implicit conversion from float 50.800000000000004 to int loses precision.

$imageWatermark = new SimpleImage();
$imageWatermark
    ->fromFile(WWW_ROOT . 'img' . DS . 'logo-watermark.png')
    ->resize($image->getWidth() / 5);

$image->overlay($imageWatermark, 'bottom right', .6, -25, -25);

This function does it: $image->overlay(...);

Thank you

a-d-w-s commented 1 year ago

If I modify the code as follows, it no longer returns the error.

  protected static function imageCopyMergeAlpha($dstIm, $srcIm, $dstX, $dstY, $srcX, $srcY, $srcW, $srcH, $pct) {
    // Are we merging with transparency?
    if($pct < 100) {
      // Disable alpha blending and "colorize" the image using a transparent color
      imagealphablending($srcIm, false);
      imagefilter($srcIm, IMG_FILTER_COLORIZE, 0, 0, 0, round(127 * ((100 - $pct) / 100)));
    }

    imagecopy($dstIm, $srcIm, (int) $dstX, (int) $dstY, (int) $srcX, (int) $srcY, (int) $srcW, (int) $srcH);

    return true;
  }

Original line:

imagefilter($srcIm, IMG_FILTER_COLORIZE, 0, 0, 0, 127 * ((100 - $pct) / 100));

claviska commented 1 year ago

Fixed in #310.