Only scale image bigger than 512px (#731)
This commit is contained in:
parent
20e1df43d0
commit
ce1e263d57
2 changed files with 5 additions and 0 deletions
|
@ -41,11 +41,13 @@ function ImagePackUpload({ onUpload }) {
|
||||||
const img = evt.target.files[0];
|
const img = evt.target.files[0];
|
||||||
if (!img) return;
|
if (!img) return;
|
||||||
setImgFile(img);
|
setImgFile(img);
|
||||||
|
shortcodeRef.current.value = img.name.slice(0, img.name.indexOf('.'));
|
||||||
shortcodeRef.current.focus();
|
shortcodeRef.current.focus();
|
||||||
};
|
};
|
||||||
const handleRemove = () => {
|
const handleRemove = () => {
|
||||||
setImgFile(null);
|
setImgFile(null);
|
||||||
inputRef.current.value = null;
|
inputRef.current.value = null;
|
||||||
|
shortcodeRef.current.value = '';
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -166,6 +166,9 @@ export function scaleDownImage(imageFile, width, height) {
|
||||||
img.onload = () => {
|
img.onload = () => {
|
||||||
let newWidth = img.width;
|
let newWidth = img.width;
|
||||||
let newHeight = img.height;
|
let newHeight = img.height;
|
||||||
|
if (newHeight <= height && newWidth <= width) {
|
||||||
|
resolve(imageFile);
|
||||||
|
}
|
||||||
|
|
||||||
if (newHeight > height) {
|
if (newHeight > height) {
|
||||||
newWidth = Math.floor(newWidth * (height / newHeight));
|
newWidth = Math.floor(newWidth * (height / newHeight));
|
||||||
|
|
Loading…
Reference in a new issue