- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/lib/File/Image/Gd.php
- Класс: BitrixMainFileImageGd
- Вызов: Gd::resize
public function resize(Rectangle $source, Rectangle $destination)
{
if ($this->resource === null)
{
return false;
}
$destinationWidth = $destination->getWidth();
$destinationHeight = $destination->getHeight();
if (($picture = imagecreatetruecolor($destinationWidth, $destinationHeight)))
{
$transparentColor = -1;
imagealphablending($picture, false);
if ($this->format == FileImage::FORMAT_PNG || $this->format == FileImage::FORMAT_WEBP)
{
$color = imagecolorallocatealpha($picture, 0, 0, 0, 127);
imagefilledrectangle($picture, 0, 0, $destinationWidth, $destinationHeight, $color);
}
elseif ($this->format == FileImage::FORMAT_GIF)
{
// save transparency
$transparentColor = $this->getTransparentColor();
if ($transparentColor >= 0)
{
$rgb = imagecolorsforindex($this->resource, $transparentColor);
$transparentColor = imagecolorallocatealpha($picture, $rgb['red'], $rgb['green'], $rgb['blue'], 127);
imagefilledrectangle($picture, 0, 0, $destinationWidth, $destinationHeight, $transparentColor);
}
}
if (imagecopyresampled($picture, $this->resource, 0, 0, $source->getX(), $source->getY(), $destinationWidth, $destinationHeight, $source->getWidth(), $source->getHeight()))
{
$this->clear();
$this->resource = $picture;
// restore transparency
if ($transparentColor >= 0)
{
$this->restoreTransparency($transparentColor);
}
return true;
}
}
return false;
}