fix: 图片工具转换图片自动去除修复旋转字段,去除旧版脚本
This commit is contained in:
@@ -41,7 +41,7 @@ function processImage(inputPath, outputPath, predetect) {
|
||||
try {
|
||||
if (type === IMAGE_TYPES.SCREENSHOT) {
|
||||
execSync(
|
||||
`magick "${inputPath}" -gravity center -quality 80 "${finalOutputPath}"`,
|
||||
`magick "${inputPath}" -auto-orient -gravity center -quality 80 "${finalOutputPath}"`,
|
||||
{ stdio: 'inherit' }
|
||||
);
|
||||
} else {
|
||||
@@ -51,7 +51,7 @@ function processImage(inputPath, outputPath, predetect) {
|
||||
? `-gravity center -resize "${target.size}^" -extent "${target.size}"`
|
||||
: `-resize "${target.size}"`;
|
||||
execSync(
|
||||
`magick "${inputPath}" ${resizeArgs} -quality 80 "${finalOutputPath}"`,
|
||||
`magick "${inputPath}" -auto-orient ${resizeArgs} -quality 80 "${finalOutputPath}"`,
|
||||
{ stdio: 'inherit' }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -63,9 +63,10 @@ function recoverExif(targetFile, sourceFile, succeedDir) {
|
||||
}
|
||||
|
||||
try {
|
||||
// 使用 exiftool 复制 EXIF 信息
|
||||
// 从原图拷 EXIF。后期软件(如美图)往往已把旋转烧进像素,
|
||||
// 若原样带回 Orientation,看图软件会再转一次;强制 Normal 避免这个坑。
|
||||
execSync(
|
||||
`exiftool -overwrite_original -all= -UserComment= -tagsFromFile "${sourceFile}" "${targetFile}"`,
|
||||
`exiftool -overwrite_original -all= -UserComment= -tagsFromFile "${sourceFile}" -Orientation=Normal "${targetFile}"`,
|
||||
{ stdio: 'inherit' }
|
||||
);
|
||||
|
||||
|
||||
@@ -34,8 +34,11 @@ function question(rl, prompt) {
|
||||
// 获取图片尺寸
|
||||
function getImageDimensions(filePath) {
|
||||
try {
|
||||
const width = execSync(`identify -format "%w" "${filePath}"`, { encoding: 'utf-8' }).trim();
|
||||
const height = execSync(`identify -format "%h" "${filePath}"`, { encoding: 'utf-8' }).trim();
|
||||
// -auto-orient:按 EXIF Orientation 换算视觉宽高,避免竖拍图被当成横图
|
||||
const output = execSync(`identify -auto-orient -format "%w %h" "${filePath}"`, {
|
||||
encoding: 'utf-8',
|
||||
}).trim();
|
||||
const [width, height] = output.split(/\s+/);
|
||||
return { width: parseInt(width), height: parseInt(height) };
|
||||
} catch (error) {
|
||||
console.error(`获取图片尺寸失败: ${filePath}`);
|
||||
|
||||
Reference in New Issue
Block a user