gpt4 book ai didi

Batch resize images and output images to new folder with ImageMagick(使用ImageMagick批量调整图像大小并将图像输出到新文件夹)

转载 作者:bug小助手 更新时间:2023-10-27 20:22:34 31 4
gpt4 key购买 nike



Current image folder path:

当前图像文件夹路径:



public_html/images/thumbs


Output image folder path:

输出图像文件夹路径:



public_html/images/new-thumbs


I have 10 video thumbs per video in current folder, named of image thumbs:

我有10个视频拇指每个视频在当前文件夹中,命名的图像拇指:



1-1.jpg
1-2.jpg
1-3.jpg
1-4.jpg
1-5.jpg (Resize)
1-6.jpg
1-7.jpg
1-8.jpg
1-9.jpg
1-10.jpg

2-1.jpg
2-2.jpg
2-3.jpg
2-4.jpg
2-5.jpg (Resize)
2-6.jpg
2-7.jpg
2-8.jpg
2-9.jpg
2-10.jpg


I want to resize all 5th images(*-5.jpg) to the new folder. I've tried below command but no luck:

我想调整所有5个图像(*-5.jpg)到新的文件夹。我试过下面的命令,但没有成功:



mogrify 
-path
public_html/images/thumbs/*-5.jpg
-resize 16×12
-quality 100
public_html/images/new-thumbs/*-5.jpg

更多回答
优秀答案推荐

"Mogrify" should be called from the directory with the original thumbnails, while the -path parameter is for pointing target directory.

应该从带有原始缩略图的目录中调用Mogrify,而-Path参数用于指向目标目录。


mkdir public_html/images/new-thumbs
cd public_html/images/thumbs
magick mogrify -resize 16x12 -quality 100 -path ../new-thumbs *.jpg

http://www.imagemagick.org/Usage/basics/#mogrify

Http://www.imagemagick.org/Usage/basics/#mogrify


The last arguments are the list of files, so you can filter by name 1-*.jpg for example.

最后一个参数是文件列表,因此您可以按名称1-*.jpg进行筛选。



Suggested solutions do not work properly on the latest ImageMagick (at least, on macOS).
Command, that works overwriting source images is as follows:

建议的解决方案在最新的ImageMagick上不能正常工作(至少在MacOS上)。覆盖源图像的命令如下所示:


magick mogrify -path ./ -resize 50% -quality 80 *.jpg

Magick mogrify-路径。/-调整50%-质量80*.jpg


To avoid overwriting the original images, write to a new folder:

为避免覆盖原始图像,请写入新文件夹:


magick mogrify -path path/to/destination/folder/ -resize 50% -quality 80 *.jpg

Magick mogrify-路径/至/目标/文件夹/-调整50%-质量80*.jpg



In ImageMagick 7 versions its built into the magick ...so..

在ImageMagick 7版本中,它内置在Magick中…所以..



magick mogrify -resize 16x12 -quality 100 -path ../new-thumbs *.jpg


Make sure that the folder you specify in path exists. It will not be created by ImageMagick.

确保您在路径中指定的文件夹存在。它不会由ImageMagick创建。



Find more information here https://www.imagemagick.org/script/mogrify.php

在此处查找更多信息https://www.imagemagick.org/script/mogrify.php



For those having Shotwell installed on Ubuntu/Debian, following may be more easy to export selected images in a folder to another folder through processing the images as needed.

对于那些在Ubuntu/Debian上安装了Shotwell的人来说,通过根据需要处理图像,以下可能更容易将一个文件夹中的选定图像导出到另一个文件夹中。




  • Open Shotwell

  • Select the images you want to export

  • File > Export

  • Adjust the values to your needs

  • Select the folder to export



In my case, I used version 7.1.1.

在我的例子中,我使用的是7.1.1版。


F:\Dataset\images>c:\"Program Files"\ImageMagick\mogrify -quality 50 -path ..\lowquality\ *

This code should be executed from the original image folder and directed to a new folder location to save.

应从原始图像文件夹执行此代码,并将其定向到要保存的新文件夹位置。


And do not forget to add "" to "Program Files" or else it will return this error

并且不要忘记将“”添加到“Program Files”中,否则它将返回此错误


c:\Program: The term 'c:\Program' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

C:\Program:术语‘c:\Program’未被识别为cmdlet、函数、脚本文件或可执行程序的名称。请检查名称的拼写,或者如果包含路径,请验证该路径是否正确,然后重试。


更多回答

You are right, but you can also call mogrify from any directory, for example I convert originary jpeg into png with mogrify -path /destination/path/ -adaptive-resize 5000 -unsharp 0x1 -format png /originary/path/*.jpeg

您是对的,但是您也可以从任何目录调用mogrify,例如,我使用mogrify-Path/ination/Path/-自适应调整大小5000-UnSharp 0x1-Format png/Origary/Path/*.jpeg将原始jpeg转换为png

Note that output directories you're pointing to must exist, as ImageMagick will no create them, causing a mogrify: unable to open image error.

请注意,您指向的输出目录必须存在,因为ImageMagick不会创建它们,从而导致mogrify:Unable to Open IMAGE错误。

Well great, I specified path but it nuked the original files nonetheless. Is there something wrong with my command line? This is Windows, hence the back slashes: mogrify -resize 2752 *.tif -path E:\1\

很好,我指定了路径,但它还是破坏了原始文件。我的命令行有问题吗?这是Windows,因此反斜杠:mogrify-resize 2752*.tif-路径E:\1\

@VioletGiraffe, options order matters, it should have been like that: mogrify -resize 2752 -path E:\1\ *.tif (note that *.tif is in the end). What you tried was like passing an image setting or operator, but it is not applicable to mogrify, afaik.

@VioletGiraffe,选项顺序很重要,它应该是这样的:mogrify -resize 2752 -path E:\1\ *.tif(注意 *.tif在最后)。你所尝试的就像传递一个图像设置或操作符,但它不适用于mogrify,afaik。

I see, thank you very much for this answer-comment as well as the main answer!

我明白了,非常感谢你的回答--评论和主要答案!

If you resize by 50% then reduce the quality by 20% then it will only be 40% of the original quality? i.e. 0.5 * 0.8

如果您将尺寸调整50%,然后将质量降低20%,那么它将只是原始质量的40%?即0.5*0.8

@PaoloTormon: No. -resize changes the size in pixels, -quality changes the compression of the file. For PNG, -quality alters the ratio between file size and time to decompress, but the format is lossless so you won't see any difference between files compressed with different "qualities". For JPEG, you will see a difference but it's more complex than making the product of the two parameters.

@PaoloTormon:不。-RESIZE更改以像素为单位的大小,-QUALITY更改文件的压缩。对于PNG,-quality改变了文件大小和解压缩时间之间的比率,但是格式是无损的,所以你看不到用不同“质量”压缩的文件之间的任何区别。对于JPEG,您将看到不同之处,但这比两个参数的乘积要复杂得多。

This is exactly the same as the accepted answer, only 4 years later. Why? (I guess you added the word "magick" to the front of it, but it runs fine without that (no added value)

这与公认的答案完全相同,只是4年后。为什么?(我猜你在前面加了“Magick”这个词,但没有这个词,它运行得很好(没有附加值)。

@ashleedawg, without magick I get Cannot find file at '..\\lib\imagemagick.tool\tools\mogrify.exe' in output in my Windows for ImageMagick 7. See this answer for details. +1 from me to mahesh madhusudan. Thanks.

@ashleedawg,如果没有Magick,我无法在我的Windows for ImageMagick 7的输出中找到位于‘..\\lib\Imagemagick.Tool\Tools\mogrify.exe’的文件。有关详细信息,请参阅此答案。+1从我到Mahesh Madhuudan。谢谢。

Thank you very much @СашаЧерных ....!!! I was trying to recollect why I had done this... as it was long back ago....

非常感谢@СашаЧерных...!我在试着回忆我为什么要这么做。就像很久以前一样……

@СашаЧерных That shouldn't require a separate answer; a comment at best.

@СашаЧерных这不应该需要单独的回答;充其量也就是一条评论。

legacy.imagemagick.org/Usage/resize go through this link also

Legacy.Imagemagick.org/用法/调整大小也请访问此链接

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com