| 1 image.gd.inc | image_gd_create_tmp(stdClass $image, $width, $height) |
Create a truecolor image preserving transparency from a provided image.
Parameters
$image: An image object.
$width: The new width of the new image, in pixels.
$height: The new height of the new image, in pixels.
Return value
A GD image handle.:
Related topics
File
- core/
modules/ system/ image.gd.inc, line 319 - GD2 toolkit for image manipulation within Backdrop.
Code
function image_gd_create_tmp(stdClass $image, $width, $height) {
$res = imagecreatetruecolor($width, $height);
if ($image->info['extension'] == 'gif') {
// Check if the original gif has transparency.
$transparent = imagecolortransparent($image->resource);
if ($transparent >= 0) {
// Convert to truecolor for easier transparency handling.
imagepalettetotruecolor($image->resource);
$transparent = imagecolortransparent($image->resource);
// As both are truecolor, we can use the same index now.
imagecolortransparent($res, $transparent);
imagefill($res, 0, 0, $transparent);
}
else {
// The original image doesn't have a transparent color set.
// Flood with the closest we have to white instead.
imagefill($res, 0, 0, imagecolorclosest($res, 255, 255, 255));
}
}
else {
if ($image->info['extension'] == 'png' || $image->info['extension'] == 'webp') {
imagealphablending($res, FALSE);
$transparency = imagecolorallocatealpha($res, 0, 0, 0, 127);
imagefill($res, 0, 0, $transparency);
imagealphablending($res, TRUE);
imagesavealpha($res, TRUE);
}
else {
imagefill($res, 0, 0, imagecolorallocate($res, 255, 255, 255));
}
}
return $res;
}