无法将模式RGBA写入JPEG如何在不转换图像格式的情况下解决此错误



我有jpg格式的图像,我不想转换为png格式来解决此错误 任何其他方法都可以解决此错误

input_image = Image.open(image_path).convert('RGBA')
txt = Image.new('RGBA', input_image.size, (255, 255, 255, 0))

实际上我想根据我的代码创建水印图像,我必须强制使用RGBA模式。 请给我解决方案

错误:无法将模式 RGBA 写入 JPEG

摘要 1 和 2:

  • 背景
    • JPG不支持alpha = transparency
    • RGBAPalpha = transparency
      • RGBA=Red Green Blue Alpha
  • 结果
    • cannot write mode RGBA as JPEG
    • cannot write mode P as JPEG
  • 溶液
    • 在保存到 JPG 之前,请丢弃alpha = transparency
      • 如:将Image转换为RGB
    • 然后保存到JPG
  • 您的代码
input_image = Image.open(image_path).convert('RGB')
txt = Image.new('RGB', input_image.size, (255, 255, 255, 0))

最新更新