You are not logged in.
Pages: 1
*EDIT* Solved, below code boxes have been updated to the code that works, thanks!
So I am working on a small script to use for a right-click option in Pcmanfm, it uses Imagemagick and Yad and is simply an image re-sizer, when you hover over an image in Pcmanfm it offers you the option "Resize Image For Web". Clicking it causes a small yad dialog to open and prompts you to enter a size, then the Imagmagick Convert script resizes it and converts it to a jpg, and adds the new size in the new copy's filename. (i.e. image.png becomes image-800x600.jpg).
It all works fine with one exception, currently when called with the .desktop action file, it drops the copy into the users Home folder instead of the current directory.
However it works perfectly if you open a terminal in the folder where the image is, and use
shrink2 name-of-image.whatever (target image file name)
it will spit out the copy right where you are at.
Any help would be greatly appreciated, no combination of output specifiers works so far in the convert command, no amount of $PWD or %f seem to work.
Here's the .desktop that calls it (*this is what I had to fix*)
[Desktop Entry]
Type=Action
Name=Resize Image For Web
Tooltip=Shrink image and convert to jpg
Icon=gprename
Profiles=resize;
[X-Action-Profile resize]
Exec=sh -c 'cd %d && shrink2 %f'
MimeTypes=image/bmp;image/gif;image/jpeg;image/png;
And here's the script which for some reason pluma (my text editor) thinks is a perl script, but that's another issue for another day, lol:
#!/bin/sh
sizebox=$(yad --form --title="Resize Image" --field="Resize to:" --width=400 --text="Enter new size (W x H in pixels, i.e. 800x600, 1024x768 etc.)")
size=$(echo $sizebox | awk 'BEGIN {FS="|" } { print $1 }')
convert $1 -resize "$size" -set filename:copy '%t-%wx%h' '%[filename:copy].jpg'
Last edited by greenjeans (2017-10-14 18:24:30)
https://sourceforge.net/projects/vuu-do/
Vuu-do GNU/Linux, minimal Devuan-based openbox systems to build on, maximal versions if you prefer your linux fully-loaded.
Please donate to support Devuan and init freedom! https://devuan.org/os/donate
Offline
I think the desktop file replaces %f with the filename, so that filename is the first argument of the command.
Therefore, you should be able to put
filename="$1"
at the beginning of your script and then use "$filename" wherever you need it in the script.
Offline
Maybe it needs the 'here' . to tell it where to make the copy(?), (like when you want to cp stuff to a directory) - just guessing, but should be quick to try.
convert $1 -resize "$size" -set filename:copy '%t-%wx%h' '%[filename:copy].jpg' .
Offline
I must have missed this the first time.
convert $1
This makes my previous advice unnecessary. (Or did you edit that?)
add
set -x
to the beginning of the script, and it will tell you everything it does. Maybe the error will be obvious.
Offline
Thanks guys, got a good link from another awesome Devuanista on IRC and found the way, had to use another double .desktop command, added a cd first to tell the shell where to execute the shrink script, so the exec line in shrink.desktop now is:
Exec=sh -c 'cd %d && shrink2 %f'
And it works great now, cool little extension for Pcmanfm I think, quick too, I just wanted something so you don't have to open gimp just to do a quick re-size.
I'll edit first post and mark solved.
But now i'm doing a similar extension just to rotate images, works but for some reason Pcmanfm isn't replacing the thumbnail preview with the correct rotated one, but that's for another post I guess.
https://sourceforge.net/projects/vuu-do/
Vuu-do GNU/Linux, minimal Devuan-based openbox systems to build on, maximal versions if you prefer your linux fully-loaded.
Please donate to support Devuan and init freedom! https://devuan.org/os/donate
Offline
Pages: 1