Upload media image orientation

default discord avatar
joelcorey
2 months ago
34

Can someone please point me to the correct place in the documentation so that images are rotated the correct way?

  • default discord avatar
    imcorfitz
    2 months ago

    This might be related to an issue I previously have had with Sharp.

    https://github.com/lovell/sharp/issues/688#issuecomment-711132913
  • default discord avatar
    joelcorey
    2 months ago

    @imcorfitz Is the easy/cheap fix here just to make sure the height is then less than the width?



    because the thumbnail is 400 by 400, so it is having the chaining issue?

  • default discord avatar
    imcorfitz
    2 months ago

    How does the file look like when you upload



    ?



    actually.. could you send me the file please? I'd like to try and upload here and see if I can fix it

  • default discord avatar
    joelcorey
    2 months ago

    Sure one sec.



    Here ya go

    001-20220709_143105.jpg
  • default discord avatar
    imcorfitz
    2 months ago

    What is your collection config?

  • default discord avatar
    joelcorey
    2 months ago
    import { MyListComponent } from '../components/admin/UploadMultiple';
    import type { CollectionConfig } from 'payload/types';
    
    const Media: CollectionConfig = {
      slug: 'media-collection',
      fields: [
        {
          name: 'name',
          type: 'text',
        },
        {
          name: 'images',
          type: 'array',
          fields: [
            {
              name: "image",
              type: "upload",
              relationTo: "media",
              required: true,
            },
            {
              name: "title",
              type: "text",
            },
            {
              name: "alt",
              type: "text",
            },
            {
              name: "caption",
              type: "text",
            },
          ]
        }
      ],
      hooks: {
        // beforeOperation: [(args) => {console.log(args)}],
       
      },
      admin: {
        useAsTitle: 'name',
        defaultColumns: [
          'name'
        ],
        group: 'Media Collection',
        components: {
          views: {
            Edit: MyListComponent
          }
        }
      },
    };
    
    export default Media;

    Work in progress

  • default discord avatar
    imcorfitz
    2 months ago

    The media collection *



    you have a

    relationTo: "media",

    - could I see the config for that?

  • default discord avatar
    joelcorey
    2 months ago
    import path from 'path';
    import type { CollectionConfig } from 'payload/types';
    
    const Media: CollectionConfig = {
      slug: 'media',
      admin: {
        useAsTitle: 'alt',
        defaultColumns: [
          'id',
          'alt'
        ],
        group: 'Icons'
      },
      upload: {
        staticURL: '/media',
        staticDir: 'media',
        disableLocalStorage: true,
        // Specify the size name that you'd like to use as admin thumbnail
        adminThumbnail: 'thumbnail',
        imageSizes: [
          {
            height: 300,
            width: 400,
            crop: 'center',
            name: 'thumbnail', 
          },
          {
            width: 900,
            height: 450,
            crop: 'center',
            name: 'sixteenByNineMedium',
          },
        ],
      },
      fields: [
        {
          name: 'alt',
          type: 'text',
        }
      ],
    };
    
    export default Media;
  • default discord avatar
    imcorfitz
    2 months ago

    Do you have the same issue still if you download the image you just sent me - from discord.. And then upload that?

  • default discord avatar
    joelcorey
    2 months ago

    let me check



    interesting. I do not.



    So that solved it. Not sure why.



    Maybe I am just dumb? Haha

  • default discord avatar
    imcorfitz
    2 months ago

    no you are not.. I think this kinda proves my previous point. Cause discord formats your image when you uppload it.



    Basically, nested within your image is a set of metadata, which might not be interpreted correctly by sharp when you upload. However, Discord solves that for the image, so when you download it again, the metadata is stripped from the image, making a correct upload.. I used to pass all images in to photoshop and export simply to strip for metadata.. So i think it relates correctly to my github reference.



    So if you could maybe send me the file over wetransfer? That doesn't strip the metadata.

  • default discord avatar
    joelcorey
    2 months ago

    sure. Send me your email?

  • default discord avatar
    imcorfitz
    2 months ago

    Sent in pm



    So yes.. I can replicate with that image in my own media collection.. Not using your configuration.



    Now I'll try and add the rotate command to the imageresizer.js in payload.. 2 sec



    Boom!

    Screenshot_2023-07-25_at_21.16.41.png
  • default discord avatar
    joelcorey
    2 months ago

    interesting. Didn't knwo there was a rotate command.

  • default discord avatar
    imcorfitz
    2 months ago

    there isn't



    it is a "bug" in the sharp library..

  • default discord avatar
    joelcorey
    2 months ago

    So how do I replicate your fix?

  • default discord avatar
    imcorfitz
    2 months ago

    Basically by adding

    .rotate()

    to the

    sharpBase

    variable in the Payload CMS image resizer module - we can resolve your particular issue. As referred to in my answer on Github.. Exactly the same.



    the rotate command without any options passed to it, will automatically rotate so sharp has the iamge as the correct orientation.



    This unfortunately is not something you can do yourself easily. This will have to be merged as a fix to the payload codebase



    @jarrod_not_jared - maybe you can have a look at this?

    Screenshot_2023-07-25_at_21.17.38.png
  • default discord avatar
    joelcorey
    2 months ago

    Fine for now and good to know all of this stuff.



    Thanks by the way!

  • default discord avatar
    imcorfitz
    2 months ago

    Most welcome mate.. Hopefully this is an easy fix..



    @jarrod_not_jared You can pull the image in question here:

    https://wetransfer.com/downloads/da02e791687573f52b84f5f193ecb65220230725191310/aee9d9c5b7d88901907b3066bbb08c7c20230725191310/5c8878?trk=TRN_TDL_01&utm_campaign=TRN_TDL_01&utm_medium=email&utm_source=sendgrid

    if you want to test this yourself.



    I have opened issue and created PR for your review.



    https://github.com/payloadcms/payload/pull/3081


    @joelcorey - the PR has been merged and a new release of Payload is out with the fix. Would you please update to the latest version and confirm whether or not your problem has been resolved? Cheers.

  • default discord avatar
    joelcorey
    2 months ago

    Hot damn! That's exciting! Will do.



    The issue persists. I tried just uploading normally on the first image, and again with imagemagik/mogrify meta data stripping on the second.



    Interestingly: it did do a 16 by 9 thumbnail image better than before this latest fix. That is new behavior.

    Screenshot_20230727_052944.png
  • default discord avatar
    imcorfitz
    2 months ago

    Are you sure you updated the payload version?



    Copying your config, this is the result I get:

    Screenshot_2023-07-27_at_14.42.55.png
    Screenshot_2023-07-27_at_14.43.02.png
    Screenshot_2023-07-27_at_14.43.01.png
  • default discord avatar
    joelcorey
    2 months ago
    {
      "name": "payload",
      "version": "1.11.7",
      "description": "Node, React and MongoDB Headless CMS and Application Framework",
  • default discord avatar
    imcorfitz
    2 months ago

    wait a sec



    hold on.



    Do me a favour.. Please try to open your payload cms in a private window and log in and try uploading the image again..



    I think what you see is a browser cached version..



    Please also note that your different image sizes are located under the "more info" button on the image

    Screenshot_2023-07-27_at_15.03.08.png
  • default discord avatar
    joelcorey
    2 months ago

    The error persists.

  • default discord avatar
    imcorfitz
    2 months ago

    -.-'

  • default discord avatar
    joelcorey
    2 months ago

    How did you update your payload install? Maybe I am being a super noob?

  • default discord avatar
    imcorfitz
    2 months ago

    yarn add payload

  • default discord avatar
    joelcorey
    2 months ago

    Yeah I don't know.

  • default discord avatar
    imcorfitz
    2 months ago

    You mind sharing your repo?

  • default discord avatar
    joelcorey
    2 months ago

    Sure. Send me your email again.

  • default discord avatar
    imcorfitz
    2 months ago

    Have you pushed all latest changes?

  • default discord avatar
    joelcorey
    2 months ago

    no apologies



    there ya go

  • default discord avatar
    imcorfitz
    2 months ago

    After a clean download and installation of your current codebase - this is the result. Works perfectly it seems.


    Maybe try and remove your node_modules folder and reinstall everything

    Screenshot_2023-07-27_at_15.39.36.png
    Screenshot_2023-07-27_at_15.40.31.png
    Screenshot_2023-07-27_at_15.40.36.png
  • default discord avatar
    joelcorey
    2 months ago

    Works! Thanks!

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.