2

The program ImageMagick has a convert command which can be used to convert the picture format. For example I have a picture test.jpg

convert test.jpg test.png

will give the test.png.

I want to add this command to the right-click menu to simplify my work. I add a item into the regedit at HKEY_CLASSES_ROOT -- * -- shell

C:\Program Files\ImageMagick-7.0.3-Q16\convert.exe -density 600 "%1" %1.png

When I run this command to file test.jpg, it will give test.jpg.png. I want to get the file test.png. How should I modify the command line?

Ice0cean
  • 133
  • 4

2 Answers2

0

I'm not sure if the shell handlers support this directly, but I would work it around with cmd that has the features needed:

cmd /d /c "for /f "delims=" %%i in ('@echo %1') do @start "" "C:\Program Files\ImageMagick-7.0.3-Q16\convert.exe" -density 600 "%1" "%%~dpni.png""
  • @echo %1 echoes the shell-supplied full path which makes it available for CMD as a processable result. The expression is in single quotes because that is what makes it a command.
  • for /f parses that result as a list of strings (containing one string), puts each (one) string into %i and allows the %~dpni that takes drive letter, path and name (but not extension) out of the %i.
  • @start is used to not make the CMD wait for the program to finish. Empty quotes after start are very required.
Community
  • 1
  • 1
GSerg
  • 76,472
  • 17
  • 159
  • 346
0

Your method is good. While You need to change the syntax a little from:

C:\Program Files\ImageMagick-7.0.3-Q16\convert.exe -density 600 "%1" %1.png

to

C:\Program Files\ImageMagick-7.0.3-Q16\convert.exe -density 600 "%1" "%~n1.png"

I Hope this will work out your problems. But, If Not - You can make a Batch file containing this command (2nd one, which is modified by me) and Save it somewhere in PC (Say "C:\MyScript.Bat")

And, Try making the key in registry as:

C:\MyScript.bat "%1"

And, THat's the flexible way of doing it. Note: The code in batch will be as:

"C:\Program Files\ImageMagick-7.0.3-Q16\convert.exe" -density 600 "%1" "%~n1.png"

Any changes you wanna make in right click context menu, You can apply with the changing the Batch file.

Hope I Helped!

  • Thanks for you answer. The first approach doesn't work and give `%~n1.png`. I tried the second approach and it doesn't work. Maybe I did some operation wrong. Can you have you try? – Ice0cean Mar 06 '17 at 00:50
  • There is already a [deleted answer](http://stackoverflow.com/a/42608388/11683) that suggests using `%~n1.png`. It does not work. The batch file should work. – GSerg Mar 06 '17 at 13:41