Skip to content

Commit

Permalink
feat: add more info on aspect ratio error and blurhash
Browse files Browse the repository at this point in the history
  • Loading branch information
BohdanK-W32 committed Oct 17, 2023
1 parent 2039f5e commit e921b9d
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 7 deletions.
41 changes: 39 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"dotenv": "^16.3.1",
"express": "^4.18.2",
"payload": "^2.0.7",
"payload-blurhash-plugin": "^1.2.0",
"payload-plugin-phone-field": "^1.0.6",
"react": "^18.2.0",
"slugify": "^1.6.6",
Expand Down
2 changes: 1 addition & 1 deletion src/collections/media/AuthorPhotos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const AuthorPhotos: CollectionConfig = {
height: 400,
},
mimeTypes: ['image/png', 'image/jpeg', 'image/webp', 'image/avif'],
formatOptions: { format: 'webp', options: { smartSubsample: true, quality: 70 } },
formatOptions: { format: 'webp', options: { smartSubsample: true, quality: 85 } },
},
admin: {
group: mediaGroup,
Expand Down
2 changes: 1 addition & 1 deletion src/collections/media/BlogMetaImages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const BlogMetaImages: CollectionConfig = {
width: 1200,
height: 630,
},
formatOptions: { format: 'webp', options: { smartSubsample: true, quality: 60 } },
formatOptions: { format: 'webp', options: { smartSubsample: true, quality: 85 } },
mimeTypes: ['image/webp', 'image/jpeg', 'image/png'],
},
admin: {
Expand Down
2 changes: 1 addition & 1 deletion src/collections/media/ProjectImages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const ProjectImages: CollectionConfig = {
},
upload: {
mimeTypes: ['image/png', 'image/jpeg', 'image/webp', 'image/avif'],
formatOptions: { format: 'webp', options: { smartSubsample: true, quality: 70 } },
formatOptions: { format: 'webp', options: { smartSubsample: true, quality: 85 } },
imageSizes: [
{
name: '700',
Expand Down
2 changes: 1 addition & 1 deletion src/collections/media/TeamMemberPhotos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const TeamMemberPhotos: CollectionConfig = {
},
upload: {
mimeTypes: ['image/png', 'image/jpeg', 'image/webp', 'image/avif'],
formatOptions: { format: 'webp', options: { smartSubsample: true, quality: 70 } },
formatOptions: { format: 'webp', options: { smartSubsample: true, quality: 85 } },
imageSizes: [
{
name: '700',
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/checkImageAspectRatio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export const checkImageAspectRatio =
const isValidAspectRatio =
imageAspectRatio - requiredAspectRatio > -0.001 && imageAspectRatio - requiredAspectRatio < 0.001;

if (!isValidAspectRatio) throw new Error(`Image aspect ratio must be ${x}:${y}`);
if (!isValidAspectRatio)
throw new Error(`Image aspect ratio must be ${x}:${y}. Image is ${data?.width}:${data?.height}`);
};
4 changes: 4 additions & 0 deletions src/payload.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from '@payloadcms/richtext-lexical';

import path from 'path';
import computeBlurhash from 'payload-blurhash-plugin';

import validationEN from 'locales/en/validation';
import validationUA from 'locales/ua/validation';
Expand Down Expand Up @@ -300,5 +301,8 @@ export default buildConfig({
.href,
tabbedUI: true,
}),
computeBlurhash({
collections: [AuthorPhotos.slug, PartnerLogos.slug, TeamMemberPhotos.slug],
}),
],
});

0 comments on commit e921b9d

Please sign in to comment.