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

Auto rotate JPG images with EXIF orientation tag #6768

Merged
merged 2 commits into from
Jul 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,22 @@ const SettingsPage = () => {
/>
</div>
</div>
<div className="row">
<div className="col-6">
<Inputs
label={formatMessage({
id: getTrad('settings.form.autoOrientation.label'),
})}
description={formatMessage({
id: getTrad('settings.form.autoOrientation.description'),
})}
name="autoOrientation"
onChange={handleChange}
type="bool"
value={modifiedData.autoOrientation}
/>
</div>
</div>

{/*
<Divider />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ const initialState = fromJS({
initialData: {
responsiveDimensions: true,
sizeOptimization: true,
autoOrientation: false,
videoPreview: false,
},
modifiedData: {
responsiveDimensions: true,
sizeOptimization: true,
autoOrientation: false,
videoPreview: false,
},
});
Expand Down
2 changes: 2 additions & 0 deletions packages/strapi-plugin-upload/admin/src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
"settings.form.responsiveDimensions.label": "Enable responsive friendly upload",
"settings.form.responsiveDimensions.description": "It automatically generates multiple formats (large, medium, small) of the uploaded asset",
"settings.form.sizeOptimization.label": "Enable size optimization (without quality loss)",
"settings.form.autoOrientation.label": "Enable auto orientation",
"settings.form.autoOrientation.description": "Automatically rotate image according to EXIF orientation tag",
"settings.form.videoPreview.label": "Preview",
"settings.form.videoPreview.description": "It will generate a six-second preview of the video (GIF)",
"settings.section.video.label": "VIDEO",
Expand Down
5 changes: 4 additions & 1 deletion packages/strapi-plugin-upload/admin/src/translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"control-card.crop": "Кадрирование",
"control-card.delete": "Удалить",
"control-card.download": "Скачать",
"control-card.replace-media": "Заменить ресурс",
"control-card.edit": "Редактировать",
"control-card.save": "Сохранить",
"form.input.label.file-alt": "Альтернативный текст",
Expand Down Expand Up @@ -58,6 +59,8 @@
"settings.form.responsiveDimensions.label": "Включить адаптивную загрузку",
"settings.form.responsiveDimensions.description": "Будут сгенерированы большое, среднее, маленькое изображение",
"settings.form.sizeOptimization.label": "Включить оптимизацию размера (без потери качества)",
"settings.form.autoOrientation.label": "Включить автоопределение ориентации",
"settings.form.autoOrientation.description": "Автоматически поворачивать изображение в соответствии с EXIF-тегом Orientation",
"settings.form.videoPreview.label": "Превью",
"settings.form.videoPreview.description": "Будет сгенерировано шестисекундное превью (GIF)",
"settings.section.video.label": "ВИДЕО",
Expand All @@ -71,4 +74,4 @@
"sort.updated_at_desc": "Сначала недавно обновлённые",
"window.confirm.close-modal.files": "Вы уверены? Некоторые файлы ещё не загружены.",
"window.confirm.close-modal.file": "Вы уверены? Изменения будут потеряны."
}
}
12 changes: 7 additions & 5 deletions packages/strapi-plugin-upload/services/image-manipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,17 @@ const generateThumbnail = async file => {
};

const optimize = async buffer => {
const { sizeOptimization = false } = await strapi.plugins.upload.services.upload.getSettings();

if (!sizeOptimization) return { buffer };
const {
sizeOptimization = false,
autoOrientation = false,
} = await strapi.plugins.upload.services.upload.getSettings();

if (!(await canBeProccessed(buffer))) {
if (!sizeOptimization || !(await canBeProccessed(buffer))) {
return { buffer };
}

return sharp(buffer)
const sharpInstance = autoOrientation ? sharp(buffer).rotate() : sharp(buffer);
return sharpInstance
.toBuffer({ resolveWithObject: true })
.then(({ data, info }) => ({
buffer: data,
Expand Down