Recognize psd file masquerading as jpg

  1. 2 months ago

    Beatrix W

    Feb 12 Pre-Release Testers Europe (Germany)

    I've got an image file with a jpg name but in reality it's a psd file with an embedded jpg. I know how to recognize a jpg. But how do I do that with a psd file? I don't need to know any details about the psd file. Just like I can do with a jpg

    if StartOfPicture.MidB(6,4) = "JFIF" or StartOfPicture.MidB(6,4) = "Exif" then
      'is jpg

    I want to make sure that the file can be displayed. As usual plugin solutions are welcome.

  2. Jeff T

    Feb 12 Pre-Release Testers Midlands of England, Europe
    OpenAsPicture()  followed by 
    if   thereturnedpicture <> nil   then

    Is how I usually handle it.

  3. Beatrix W

    Feb 12 Pre-Release Testers Europe (Germany)

    @Jeff Tullin: that part of my code is working. I check if I can do a preview. If there is no preview then I get the icon for the file extension. But how do I get a preview for the file/data?

  4. Christian S

    Feb 12 Pre-Release Testers, Xojo Pro, XDC Speakers Germany

    @Jeff T Is how I usually handle it.

    You may read a 200 MB file from a network volume just to check whether it may be a readable image?
    Block the app for maybe 10 seconds here?

    For PSD, a check in the first bytes may also decide this.

    From my C++ code library:

    bool IsPSD(void* data, size_t len)
    {
    	return (len>6) && (memcmp(data, "8BPS", 4) == 0);
    }
  5. Jeff T

    Feb 12 Pre-Release Testers Midlands of England, Europe

    You may read a 200 MB file from a network volume just to check whether it may be a readable image?

    Only if Im trying to actually use it. :)
    The file open dialog usually has a preview available.
    I wouldn't use that method if I was trying to write a 'preview the contents of this folder' application.

  6. Beatrix W

    Feb 12 Pre-Release Testers Europe (Germany)

    @ChristianSchmitz : this doesn't seem to fit my file.

    -image-

  7. Tim J

    Feb 12 Pre-Release Testers, Xojo Pro Dehydrating in AZ

    Do you have other files of this type? Do those first 6 bytes match for all of them?

  8. Christian S

    Feb 12 Pre-Release Testers, Xojo Pro, XDC Speakers Germany

    All photoshop files I have here show 8BPS as first bytes.

  9. Sam R

    Feb 12 Pre-Release Testers, Xojo Pro Hengchun, Pingtung, Taiwan

    @ChristianSchmitz All photoshop files I have here show 8BPS as first bytes.

    I don't think that this file is a normal PSD.

    @Beatrix W I've got an image file with a jpg name but in reality it's a psd file with an embedded jpg. I know how to recognize a jpg. But how do I do that with a psd file? I don't need to know any details about the psd file. Just like I can do with a jpg

    If you're targeting the macOS only, you can use CGImageSource to read/create the preview, I'm pretty certain that you have the MBS plugin, so check with Christian on how to do. You can also use Spotlight to read the preview.

    But my gut is telling me that this file is wrapped in some kind of container and the option I suggested may not work if that's the case.

  10. Beatrix W

    Feb 12 Pre-Release Testers Europe (Germany)

    @Christian Schmitz: 8BPS seems to be the normal PSD marker.

    I think that Sam is correct. The file seems to be special. It came in a special mail:

    Content-Type: text/plain
    Content-ID: <B9C738D7CA24964EA7623AAA79BDD982@tamhsc.edu>
    Content-Disposition: inline; filename="SPH Mission Sign (DS).jpg"
    Content-Transfer-Encoding: base64

    First my software tried to show this as text. Then after fixing this problem Graphics magic borked on the image. CGImageSource also doesn't like the file. The image can be opened with GraphicsConverter but my software isn't a graphics software. The user gets the file and I'll close the ticket.

or Sign Up to reply!