Столкнулся с той же самой проблемой, но для png
Проблемы были с прозрачностью, доработал решение так
[CODE]if (stripos($cacheImageFileTmp, 'png') !== false) {
$maxColor = 251;
$oldImg = imagecreatefrompng($cacheImageFileTmp);
$sizes = getimagesize($cacheImageFileTmp);
$newImg = imagecreatetruecolor($sizes[0], $sizes[1]);
imagealphablending($newImg, false);
imagesavealpha($newImg, true);
imagecopyresampled($newImg, $oldImg, 0, 0, 0, 0, $sizes[0], $sizes[1], $sizes[0], $sizes[1]);
$colorWhite = imagecolorallocate($newImg, 255, 255, 255);
for ($y = 0; $y < ($sizes[1]); ++$y) {
for ($x = 0; $x < ($sizes[0]); ++$x) {
$isTransparent = false;
$colorat = imagecolorat($newImg, $x, $y);
if(($colorat & 0x7F000000) >> 24) {
$isTransparent = true;
}
$r = ($colorat >> 16) & 0xFF;
$g = ($colorat >> 8) & 0xFF;
$b = $colorat & 0xFF;
// Если цвет пикселя нас не устраивает, заменяем его на белый
if (($r >= $maxColor && $g >= $maxColor && $b >= $maxColor) || ($isTransparent)) {
imagesetpixel($newImg, $x, $y, $colorWhite);
}
}
}
imagepng($newImg, $cacheImageFileTmp, 9);
}
[/CODE]
Проблемы были с прозрачностью, доработал решение так
[CODE]if (stripos($cacheImageFileTmp, 'png') !== false) {
$maxColor = 251;
$oldImg = imagecreatefrompng($cacheImageFileTmp);
$sizes = getimagesize($cacheImageFileTmp);
$newImg = imagecreatetruecolor($sizes[0], $sizes[1]);
imagealphablending($newImg, false);
imagesavealpha($newImg, true);
imagecopyresampled($newImg, $oldImg, 0, 0, 0, 0, $sizes[0], $sizes[1], $sizes[0], $sizes[1]);
$colorWhite = imagecolorallocate($newImg, 255, 255, 255);
for ($y = 0; $y < ($sizes[1]); ++$y) {
for ($x = 0; $x < ($sizes[0]); ++$x) {
$isTransparent = false;
$colorat = imagecolorat($newImg, $x, $y);
if(($colorat & 0x7F000000) >> 24) {
$isTransparent = true;
}
$r = ($colorat >> 16) & 0xFF;
$g = ($colorat >> 8) & 0xFF;
$b = $colorat & 0xFF;
// Если цвет пикселя нас не устраивает, заменяем его на белый
if (($r >= $maxColor && $g >= $maxColor && $b >= $maxColor) || ($isTransparent)) {
imagesetpixel($newImg, $x, $y, $colorWhite);
}
}
}
imagepng($newImg, $cacheImageFileTmp, 9);
}
[/CODE]