[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
  1. \ backslash, the next character is literal and not subject to interpretation
  2. \n newline
  3. \r carriage return
  4. < less-than character.
  5. > greater-than character.
  6. & ampersand character.
  7. %% a percent sign
  8. %b file size of image read in (use -precision 16 to force results in B)
  9. %c comment meta-data property
  10. %d directory component of path
  11. %e filename extension or suffix
  12. %f filename (including suffix)
  13. %g layer canvas page geometry (equivalent to "%Wx%H%X%Y")
  14. %h current image height in pixels
  15. %i image filename (note: becomes output filename for "info:")
  16. %k CALCULATED: number of unique colors
  17. %l label meta-data property
  18. %m image file format (file magic)
  19. %n number of images in current image sequence, report once per frame
  20. %o output filename (used for delegates)
  21. %p index of image in current image list
  22. %q quantum depth (compile-time constant)
  23. %r image class and colorspace
  24. %s scene number (from input unless re-assigned)
  25. %t filename without directory or extension (suffix)
  26. %u unique temporary filename (used for delegates)
  27. %w current width in pixels
  28. %x x resolution (density)
  29. %y y resolution (density)
  30. %z image depth (as read in unless modified, image save depth)
  31. %A image transparency channel. Values include Undefined (no transparency channel), Blend, Copy, or Update.
  32. %B file size of image read in bytes
  33. %C image compression type
  34. %D image GIF dispose method
  35. %G original image size (%wx%h; before any resizes)
  36. %H page (canvas) height
  37. %M Magick filename (original file exactly as given, including read mods)
  38. %N number of images in current image sequence, report once per image sequence
  39. %O page (canvas) offset ( = %X%Y )
  40. %P page (canvas) size ( = %Wx%H )
  41. %Q image compression quality ( 0 = default )
  42. %S ?? scenes ??
  43. %T image time delay (in centi-seconds)
  44. %U image resolution units
  45. %W page (canvas) width
  46. %X page (canvas) x offset (including sign)
  47. %Y page (canvas) y offset (including sign)
  48. %Z unique filename (used for delegates)
  49. %@ CALCULATED: trim bounding box (without actually trimming)
  50. %# CALCULATED: 'signature' hash of image values
  51. https://imagemagick.org/script/escape.php
复制代码


之前见过buyiyang大佬用exiftool,工具自带参数打印文件名
查了下资料,magick也可以
  1. @echo off
  2. rem 批处理保存为utf-8编码格式,自行设置magick变量
  3. chcp 65001
  4. for /f "tokens=1-2*" %%a in ('magick identify -format "%%w %%h %%i\n" *.jpg') do (
  5. echo w=%%a
  6. echo h=%%b
  7. echo name=%%c
  8. )
  9. pause
复制代码
1

评分人数

bat小白,请多指教!谢谢!

TOP

  1. magick identify -format "%%w %%h %%i\n" *.jpg
复制代码

这个命令有点奇怪,用for /f 读取正常显示中文文件名,单独执行不行。
如果 set magick=d:\1\magick.exe,也有点奇怪
给=号后加引号或者不加,路径是否包含空格 等等组合情况,有时候需要用 4个% 才行  for /f in (%%magick%%)
bat小白,请多指教!谢谢!

TOP

本帖最后由 77七 于 2023-9-1 23:23 编辑

回复 6# buyiyang

谢谢大佬指点!我开始是 code1 这样测试的。发现 4个 % 能兼容 set 1-3。参考您的帖子,发现简单问题被我搞复杂了,如code2 第二条命令,外加引号就行。

我用的版本是 ImageMagick-7.1.1-9-portable-Q8-x64
  1. rem code1
  2. @echo off
  3. chcp 65001 >nul
  4. set magick1="D:\新建文件夹\magick.exe"
  5. set magick1="D:\新建文 件夹\magick.exe"
  6. set magick1=D:\新建文件夹\magick.exe
  7. rem set magick1=D:\新建文 件夹\magick.exe
  8. for /f "tokens=1-2*" %%a in ('%%magick1%% identify -format "%%w %%h %%i\n" *.jpg') do echo %%a %%b %%c
  9. pause
  10. rem code2
  11. rem 错误
  12. for /f "tokens=1-2*" %%a in ('"D:\新建文 件夹\magick.exe" identify -format "%%w %%h %%i\n" *.jpg') do echo %%a %%b %%c
  13. rem 正确
  14. for /f "tokens=1-2*" %%a in ('""D:\新建文 件夹\magick.exe" identify -format "%%w %%h %%i\n" *.jpg"') do echo %%a %%b %%c
  15. pause
  16. ::结果
  17. 1920 1400 1.jpg
  18. 1920 1400 2.jpg
  19. 5184 2920 4k壁纸aa深蓝.jpg
  20. Press any key to continue . . .
  21. 'D:\新建文' is not recognized as an internal or external command,
  22. operable program or batch file.
  23. 1920 1400 1.jpg
  24. 1920 1400 2.jpg
  25. 5184 2920 4k壁纸aa深蓝.jpg
复制代码
bat小白,请多指教!谢谢!

TOP

本帖最后由 77七 于 2023-9-1 23:17 编辑

回复 7# Five66


   谢谢大佬指点!
  1. magick identify -format "%%w %%h %%i\n" *.jpg>1.txt
复制代码


将命令结果重定向到文本,正确显示中文,1.txt编码utf-8。是个处理结果的好方法!
试了下,加个管道也在cmd窗口正常显示了。

  1. @echo off
  2. chcp 65001 >nul
  3. magick identify -format "%%w %%h %%i\n" *.jpg|findstr .
  4. pause
复制代码
bat小白,请多指教!谢谢!

TOP

返回列表