Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving a PSB larger than 30,000 pixels results in an invalid file #246

Closed
abrahamavnisan opened this issue Aug 31, 2020 · 1 comment · Fixed by #249
Closed

Saving a PSB larger than 30,000 pixels results in an invalid file #246

abrahamavnisan opened this issue Aug 31, 2020 · 1 comment · Fixed by #249
Labels

Comments

@abrahamavnisan
Copy link

Describe the bug
I am trying to use Pillow to composite very large gigapixel image files, then save them in the PSB format using psd-tools.

When the image I save to psb is less than 30,000 pixels wide, I have no issues. As soon as my image is greater than 30,000 pixels, however, the psb file saved will not open in Photoshop, which gives me a "Could not complete your request because the file is not compatible with this version of Photoshop" error message.

According to this site, the difference between the psd and psb formats is that psd's support up to 30,000 pixel wide images, whereas psb's support up to 300,000 pixel wide images. This leads me to believe that there is a bug wherein psd-tools can only save psb images that fall under the psd size limit of 30,000 pixels.

To Reproduce
Steps to reproduce the behavior:

from PIL import Image
from psd_tools import PSDImage
import requests 

# grab a png from the web to tile into a large image file
imageURL = "https://linkscafeu.files.wordpress.com/2015/06/super-mario-bros-png.png"
imageFile = requests.get(imageURL)
open('mario.png', 'wb').write(imageFile.content)

# open the image using Pillow and extract dimensions
tileImage = Image.open('mario.png')

size = tileImage.size
tileImageWidth = size[0]
tileImageHeight = size[1]

# create a new pillow image object that meets psd's 30,000 pixel maximum
finalImageSmaller = Image.new('RGB', (30000, tileImageHeight))

# paste the image horizontally until it fills the canvas
xOffset = 0
while xOffset < 30000:
    finalImageSmaller.paste(tileImage, (xOffset, 0))
    xOffset += tileImageWidth

psd = PSDImage.frompil(finalImageSmaller)
psd.save("finalImageSmaller.psb")

# create a new pillow image object that exceeds psd's 30,000 pixel maximum,
# but which is smaller than psb's 300,000 pixel maximum
finalImageLarger = Image.new('RGB', (30500, tileImageHeight))

# paste the image horizontally until it fills the canvas
xOffset = 0
while xOffset < 30500:
    finalImageLarger.paste(tileImage, (xOffset, 0))
    xOffset += tileImageWidth

psd = PSDImage.frompil(finalImageLarger)
psd.save("finalImageLarger.psb")

Expected behavior
Photoshop should be able to open both finalImageSmaller.psb and finalImageLarger.psb.

File and screenshots
These are the two PSB files produced by the above script, as a zip

This is the error I receive in Photoshop when trying to open the larger PSB:

Screen Shot 2020-08-31 at 10 40 43 AM

Environment

  • Python [3.8.4]
  • Version [v1.9.15]
  • Photoshop [CC 20.0.6]
  • MacOS [10.14.6]
@kyamagu
Copy link
Contributor

kyamagu commented Sep 1, 2020

Creating a new PSD/PSB file is not tested at all and expect bugs. The bug is that frompil method expects a PSD (not PSB) format, and internally there is a flag that specifies the format in the header section.

For this workload, I would recommend directly opening an image file in Photoshop at this moment.

@kyamagu kyamagu added the bug label Sep 1, 2020
@kyamagu kyamagu mentioned this issue Sep 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants