protected static function _downscaleGif($source, $width, $height, $target, $targetWidth, $targetHeight)
    {
        $sourceImage = @imagecreatefromgif($source);
        $targetImage = imagecreatetruecolor($targetWidth, $targetHeight);

        // Determine the transparent color
        $sourceTransparentIndex = imagecolortransparent($sourceImage);
        $sourceTransparentColor = ($sourceTransparentIndex >= 0) ? imagecolorsforindex($sourceImage,
            $sourceTransparentIndex) : null;

        // Allocate transparency for the target image if needed
        if ($sourceTransparentColor !== null) {
            $targetTransparentColor = imagecolorallocate($targetImage, $sourceTransparentColor['red'],
                $sourceTransparentColor['green'], $sourceTransparentColor['blue']);
            $targetTransparentIndex = imagecolortransparent($targetImage, $targetTransparentColor);
            imageFill($targetImage, 0, 0, $targetTransparentIndex);
        }

        // Resize & resample the image (no sharpening)
        imagecopyresampled($targetImage, $sourceImage, 0, 0, 0, 0, $targetWidth, $targetHeight, $width, $height);

        // Save the target GIF image
        $saved = imagegif($targetImage, $target);

        // Destroy the source image descriptor
        imagedestroy($sourceImage);

        // Destroy the target image descriptor
        imagedestroy($targetImage);

        return $saved;
    }