mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 08:52:26 +00:00
Auto rotate JPEG images
Signed-off-by: alxnkt <alxnkt@mail.ru>
This commit is contained in:
parent
cd710d34e0
commit
65293fd21c
@ -144,6 +144,19 @@ const SettingsPage = () => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="row">
|
||||||
|
<div className="col-6">
|
||||||
|
<Inputs
|
||||||
|
label={formatMessage({
|
||||||
|
id: getTrad('settings.form.autoOrientation.label'),
|
||||||
|
})}
|
||||||
|
name="autoOrientation"
|
||||||
|
onChange={handleChange}
|
||||||
|
type="bool"
|
||||||
|
value={modifiedData.autoOrientation}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{/*
|
{/*
|
||||||
<Divider />
|
<Divider />
|
||||||
|
@ -5,11 +5,13 @@ const initialState = fromJS({
|
|||||||
initialData: {
|
initialData: {
|
||||||
responsiveDimensions: true,
|
responsiveDimensions: true,
|
||||||
sizeOptimization: true,
|
sizeOptimization: true,
|
||||||
|
autoOrientation: false,
|
||||||
videoPreview: false,
|
videoPreview: false,
|
||||||
},
|
},
|
||||||
modifiedData: {
|
modifiedData: {
|
||||||
responsiveDimensions: true,
|
responsiveDimensions: true,
|
||||||
sizeOptimization: true,
|
sizeOptimization: true,
|
||||||
|
autoOrientation: false,
|
||||||
videoPreview: false,
|
videoPreview: false,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -64,6 +64,7 @@
|
|||||||
"settings.form.responsiveDimensions.label": "Enable responsive friendly upload",
|
"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.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.sizeOptimization.label": "Enable size optimization (without quality loss)",
|
||||||
|
"settings.form.autoOrientation.label": "Enable auto orientation",
|
||||||
"settings.form.videoPreview.label": "Preview",
|
"settings.form.videoPreview.label": "Preview",
|
||||||
"settings.form.videoPreview.description": "It will generate a six-second preview of the video (GIF)",
|
"settings.form.videoPreview.description": "It will generate a six-second preview of the video (GIF)",
|
||||||
"settings.section.video.label": "VIDEO",
|
"settings.section.video.label": "VIDEO",
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
"control-card.crop": "Кадрирование",
|
"control-card.crop": "Кадрирование",
|
||||||
"control-card.delete": "Удалить",
|
"control-card.delete": "Удалить",
|
||||||
"control-card.download": "Скачать",
|
"control-card.download": "Скачать",
|
||||||
|
"control-card.replace-media": "Заменить ресурс",
|
||||||
"control-card.edit": "Редактировать",
|
"control-card.edit": "Редактировать",
|
||||||
"control-card.save": "Сохранить",
|
"control-card.save": "Сохранить",
|
||||||
"form.input.label.file-alt": "Альтернативный текст",
|
"form.input.label.file-alt": "Альтернативный текст",
|
||||||
@ -58,6 +59,7 @@
|
|||||||
"settings.form.responsiveDimensions.label": "Включить адаптивную загрузку",
|
"settings.form.responsiveDimensions.label": "Включить адаптивную загрузку",
|
||||||
"settings.form.responsiveDimensions.description": "Будут сгенерированы большое, среднее, маленькое изображение",
|
"settings.form.responsiveDimensions.description": "Будут сгенерированы большое, среднее, маленькое изображение",
|
||||||
"settings.form.sizeOptimization.label": "Включить оптимизацию размера (без потери качества)",
|
"settings.form.sizeOptimization.label": "Включить оптимизацию размера (без потери качества)",
|
||||||
|
"settings.form.autoOrientation.label": "Включить автоопределение ориентации",
|
||||||
"settings.form.videoPreview.label": "Превью",
|
"settings.form.videoPreview.label": "Превью",
|
||||||
"settings.form.videoPreview.description": "Будет сгенерировано шестисекундное превью (GIF)",
|
"settings.form.videoPreview.description": "Будет сгенерировано шестисекундное превью (GIF)",
|
||||||
"settings.section.video.label": "ВИДЕО",
|
"settings.section.video.label": "ВИДЕО",
|
||||||
|
@ -59,15 +59,17 @@ const generateThumbnail = async file => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const optimize = async buffer => {
|
const optimize = async buffer => {
|
||||||
const { sizeOptimization = false } = await strapi.plugins.upload.services.upload.getSettings();
|
const {
|
||||||
|
sizeOptimization = false,
|
||||||
|
autoOrientation = false,
|
||||||
|
} = await strapi.plugins.upload.services.upload.getSettings();
|
||||||
|
|
||||||
if (!sizeOptimization) return { buffer };
|
if (!sizeOptimization || !(await canBeProccessed(buffer))) {
|
||||||
|
|
||||||
if (!(await canBeProccessed(buffer))) {
|
|
||||||
return { buffer };
|
return { buffer };
|
||||||
}
|
}
|
||||||
|
|
||||||
return sharp(buffer)
|
const sharpInstance = autoOrientation ? sharp(buffer).rotate() : sharp(buffer);
|
||||||
|
return sharpInstance
|
||||||
.toBuffer({ resolveWithObject: true })
|
.toBuffer({ resolveWithObject: true })
|
||||||
.then(({ data, info }) => ({
|
.then(({ data, info }) => ({
|
||||||
buffer: data,
|
buffer: data,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user