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

        // Enable interlacing for progressive JPEGs
        imageinterlace($targetImage, true);

        // Resize, resample and sharpen the image
        imagecopyresampled($targetImage, $sourceImage, 0, 0, 0, 0, $targetWidth, $targetHeight, $width, $height);
        self::_sharpenImage($targetImage, $width, $targetWidth);

        // Save the target JPEG image
        $saved = imagejpeg($targetImage, $target, min(100, max(1, intval(SQUEEZR_IMAGE_JPEG_QUALITY))));

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

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

        return $saved;
    }