ฉันพยายามใช้ ImageMagick จากบรรทัดคำสั่งใน Windows 7 เพื่อแปลงภาพหลายภาพในครั้งเดียว ฉันต้องการใช้อินเทอร์เฟซตัวเลือก - ชุด แต่ฉันได้รับผลลัพธ์ที่ไม่คาดคิด ตัวอย่างสั้น ๆ ของความแปลกประหลาดบางอย่างที่ฉันเห็นคือ:
C:\>convert example.jpg -verbose -set filename:foo hello -set filename:bar world "%[filename:foo]_%[filename:bar].png"
example.jpg=>helloworld.png JPEG 352x264 352x264+0+0 8-bit DirectClass 131KB 0.125u 0:00.135
โปรดสังเกตว่าอักขระขีดล่างจะถูกลบอย่างลึกลับจากชื่อไฟล์เอาต์พุต ฉันสามารถใช้เครื่องหมายรูปหมวก (^) เพื่อหนีเครื่องหมายเปอร์เซ็นต์ที่สองเพื่อรักษาขีดล่าง:
C:\>convert example.jpg -verbose -set filename:foo hello -set filename:bar world "%[filename:foo]_^%[filename:bar].png"
example.jpg=>hello_world.png JPEG 352x264 352x264+0+0 8-bit DirectClass 131KB 0.125u 0:00.126
เกิดอะไรขึ้นที่นี่? ทำไมการแทรกเครื่องหมายรูปหมวกจะทำให้ขีดเส้นใต้ถูกเก็บรักษาไว้? เครื่องหมายรูปหมวก (^) แม้แต่ escaper ที่ถูกต้องที่จะลองหรือไม่? พฤติกรรมนี้เกิดจากการขยายตัวของตัวแปรสภาพแวดล้อมของเชลล์คำสั่งหรือความแปลกประหลาดเป็นผลมาจากวิธีที่ ImageMagick จัดการกับค่าเปอร์เซ็นต์ ไม่ว่าจะด้วยวิธีใดมีหลักการทั่วไปเกี่ยวกับการใช้สัญลักษณ์ร้อยละในบรรทัดคำสั่งที่สามารถติดตามเพื่อทำให้เกิดพฤติกรรมที่คาดการณ์ได้หรือไม่
สิ่งที่ฉันต้องการทำจริง ๆ คือเวอร์ชันของคำสั่งด้านบนที่มีชุดคุณสมบัติมากมายอีกมากมายที่สามารถจัดการชื่อไฟล์ที่มีอักขระพิเศษเช่นช่องว่างและสัญลักษณ์เปอร์เซ็นต์ได้ แต่ดูเหมือนโง่มากที่จะลองว่า . ในที่สุดฉันจะต้องดำเนินการคำสั่งจากโปรแกรม. NET
ฉันดูที่http://www.robvanderwoude.com/escapechars.phpและEscaping% ในชื่อไฟล์ / ชื่อโฟลเดอร์ที่บรรทัดคำสั่งแต่ไม่สามารถหาวิธีใช้คำแนะนำกับปัญหาของฉันได้
ปรับปรุง
การเพิ่มตัวอย่างเพิ่มเติมเพื่อตอบคำถามในความคิดเห็นจาก @dbenham และ @Synetech
การย้ายเครื่องหมายขีดล่างจากหน้าเครื่องหมายเปอร์เซ็นต์ที่สองตามตัวอย่างหลังด้านบนไปยังเครื่องหมายขีดล่างสร้างไฟล์ชื่อhello^world.png
:
C:\>convert example.jpg -verbose -set filename:foo hello -set filename:bar world "%[filename:foo]^_%[filename:bar].png"
example.jpg=>hello^world.png JPEG 352x264 352x264+0+0 8-bit DirectClass 131KB 0.141u 0:00.132
การหลีกเลี่ยงเครื่องหมายอัญประกาศล้อมรอบอยู่เสมอจะส่งผลให้เสมอhelloworld.png
โดยไม่คำนึงว่าวาง carets ไว้ภายใน:
C:\>convert example.jpg -verbose -set filename:foo hello -set filename:bar world ^"^%[filename:foo]_^%[filename:bar].png^"
example.jpg=>helloworld.png JPEG 352x264 352x264+0+0 8-bit DirectClass 131KB 0.109u 0:00.115
C:\>convert example.jpg -verbose -set filename:foo hello -set filename:bar world ^"%[filename:foo]_^%[filename:bar].png^"
example.jpg=>helloworld.png JPEG 352x264 352x264+0+0 8-bit DirectClass 131KB 0.141u 0:00.143
C:\>convert example.jpg -verbose -set filename:foo hello -set filename:bar world ^"^%[filename:foo]_%[filename:bar].png^"
example.jpg=>helloworld.png JPEG 352x264 352x264+0+0 8-bit DirectClass 131KB 0.125u 0:00.126
C:\>convert example.jpg -verbose -set filename:foo hello -set filename:bar world ^"%[filename:foo]_%[filename:bar].png^"
example.jpg=>helloworld.png JPEG 352x264 352x264+0+0 8-bit DirectClass 131KB 0.125u 0:00.131
C:\>convert example.jpg -verbose -set filename:foo hello -set filename:bar world ^"%[filename:foo]^_%[filename:bar].png^"
example.jpg=>helloworld.png JPEG 352x264 352x264+0+0 8-bit DirectClass 131KB 0.125u 0:00.111
^"^%[filename:foo]_^%[filename:bar].png^"