Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implicit conversion from float 50.800000000000004 to int loses precision #307

Closed
a-d-w-s opened this issue Oct 28, 2022 · 2 comments
Closed

Comments

@a-d-w-s
Copy link
Contributor

a-d-w-s commented Oct 28, 2022

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
Copy link
Contributor Author

a-d-w-s commented Nov 28, 2022

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
Copy link
Owner

Fixed in #310.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants