nystudio107 / craft-seomatic

SEOmatic facilitates modern SEO best practices & implementation for Craft CMS 3. It is a turnkey SEO system that is comprehensive, powerful, and flexible.
https://nystudio107.com/plugins/seomatic
Other
162 stars 68 forks source link

Using seomatic.helper.socialTransform with non PNG or JPG image and no transform name results in error #1411

Closed kerrig closed 4 months ago

kerrig commented 5 months ago

Site is using seomatic.helper.socialTransform with an image from a field in the CMS. The image is a webp and the code is not calling a specific transform which is causing the template to throw an error:

Screenshot 2024-02-05 at 11 19 21 AM

The two main issues are because:

This is the code thats calling socialTransform: {% do seomatic.meta.seoImage(seomatic.helper.socialTransform(seoImage)) %}

Here's the code that's failing (in src/helpers/ImageTransform.php):

if (!in_array($mimeType, self::ALLOWED_SOCIAL_MIME_TYPES, false)) {
     $transform->format = self::DEFAULT_SOCIAL_FORMAT;
}

Here's what I did to get it to work:

if (!in_array($mimeType, self::ALLOWED_SOCIAL_MIME_TYPES, false) && $transform !== null) {
     $transform->format = self::DEFAULT_SOCIAL_FORMAT;
}

Once I added the check that transform isn't null, it worked without issue and the SEO Image gets properly set with the webp image.

Versions

khalwat commented 4 months ago

So at the time, the various social media sites did not allow for webp images, but rather just image/jpeg, image/gif or image/png

It looks like since then, Facebook and Twitter have added support for image/webp so I think he best solution is to add that to the allowed types.

khalwat commented 4 months ago

Craft CMS 3:

You can try it now by setting your semver in your composer.json to look like this:

    "nystudio107/craft-seomatic": "dev-develop as 3.4.70”,

Then do a composer clear-cache && composer update

…..

Craft CMS 4:

You can try it now by setting your semver in your composer.json to look like this:

    "nystudio107/craft-seomatic": "dev-develop-v4 as 4.0.39”,

Then do a composer clear-cache && composer update

…..

Craft CMS 5:

You can try it now by setting your semver in your composer.json to look like this:

    "nystudio107/craft-seomatic": "dev-develop-v5 as 5.0.0-beta.3”,

Then do a composer clear-cache && composer update

kerrig commented 4 months ago

@khalwat Tested and confirmed it's working! Thanks for the quick turnaround