Page 1 of 1
Image resizing :: another problem
Posted: 2008-11-03T11:19:46-07:00
by sim123
I don't know if I am doing something wrong again, I want an image to scale (resize or thumbnail) only if it's width and height dimensions are greater than 200/ 100. Here is the image I am using, which is 45 x 45 so theoretically there shouldn't be any conversions, I just need same image with a different name.
http://www.huffingtonpost.com/contribut ... adshot.jpg
Here is the command
convert headshot.jpg -resize 200x200 > -write headshot_f.jpg -thumbnail 100x100 > headshot_t.jpg
I get an error saying
convert: option requires an argument `-thumbnail'.
if I try only resize option
convert headshot.jpg -resize 200x200 > -write headshot_f.jpg
then image is converted into 200x200 dimensions??
Please help.
Thanks for all the help and support.
Re: Image resizing :: another problem
Posted: 2008-11-03T11:27:39-07:00
by el_supremo
There should not be a space between 200x200 and the > and it would be best to put quotes around it as well so the shell doesn't interpret it as I/O redirection
Try:
Code: Select all
convert headshot.jpg -resize "200x200>" -write headshot_f.jpg -thumbnail "100x100>" headshot_t.jpg
If you're using Linux, you might need to use single quotes instead of double quotes.
Pete
Re: Image resizing :: another problem
Posted: 2008-11-03T11:28:39-07:00
by fmw42
sim123 wrote:I don't know if I am doing something wrong again, I want an image to scale (resize or thumbnail) only if it's width and height dimensions are greater than 200/ 100. Here is the image I am using, which is 45 x 45 so theoretically there shouldn't be any conversions, I just need same image with a different name.
http://www.huffingtonpost.com/contribut ... adshot.jpg
Here is the command
convert headshot.jpg -resize 200x200 > -write headshot_f.jpg -thumbnail 100x100 > headshot_t.jpg
I get an error saying
convert: option requires an argument `-thumbnail'.
if I try only resize option
convert headshot.jpg -resize 200x200 > -write headshot_f.jpg
then image is converted into 200x200 dimensions??
Please help.
Thanks for all the help and support.
You have a space between 200x200 and >. Close the space. 200x200>
You may also need an escape character if that does not solve it. Use \ on Unix and I think ^ on Windows as escape characters, e.g. 200x200\> But try first without.
Re: Image resizing :: another problem
Posted: 2008-11-03T12:02:59-07:00
by sim123
Thank you so much for quick response, I appreciate your help.
-I tried putting quotes
Code: Select all
convert headshot.jpg -resize "200x200>" -write headshot_f.jpg -thumbnail "100x100>" headshot_t.jpg
and it worked but I am using Java (Runtime.exec) to execute these commands, MAC for development and Linux for deployment so I want more generic solution.
I tried removing spaces, it didn't work, then put escape sequence ("\") which is working fine, just wanted to know that this escape character will work same way on linux or I need another character for Linux?
Thanks for all the help and support.
Re: Image resizing :: another problem
Posted: 2008-11-03T12:13:20-07:00
by sim123
This escape sequence is not working with Runtime.exec, here is the code
Code: Select all
private static void convert(String imageToResize, String thumbnail1ImageOut, String thumbnailImageOut) {
ArrayList<String> command = new ArrayList<String>(10);
try{
command.add("/usr/local/bin/convert");
command.add(imageToResize);
command.add("-resize");
command.add("200x200\\>");
command.add("-write");
command.add(thumbnail1ImageOut);
command.add("-thumbnail");
command.add("100x100\\>");
command.add(thumbnailImageOut);
}catch(Exception e){
e.printStackTrace();
}
exec((String[])command.toArray(new String[1]));
command = new ArrayList<String>(10);
}
private static boolean exec(String[] command) {
Process proc;
try {
System.out.println("command" + Arrays.asList(command));
proc = Runtime.getRuntime().exec(command);
} catch (Exception e) {
e.printStackTrace();
return false;
}
int exitStatus;
while (true) {
try {
exitStatus = proc.waitFor();
break;
} catch (java.lang.InterruptedException e) {
System.out.println("exception");
e.printStackTrace();
}
}
if (exitStatus != 0) {
System.out.println("Error executing command: " + exitStatus);
}
return (exitStatus == 0);
}
And I am qurious to know why this is not happening if my image size is greater than 200x200 pixels?
If image is big then everything is working fine even with space in 200x200 > .
Thanks for all the help and support.
Re: Image resizing :: another problem
Posted: 2008-11-03T12:22:27-07:00
by sim123
I tried without escape sequence after removing space from "200x200 >", and its seems to be working
Sorry for the trouble, but just want to know, why this space character throws an error only if image size is less than 200x200, if image size is bigger then scaling works fine.
Thanks for your time, help and support.
Re: Image resizing :: another problem
Posted: 2008-11-03T13:25:29-07:00
by fmw42
sim123 wrote:I tried without escape sequence after removing space from "200x200 >", and its seems to be working
Sorry for the trouble, but just want to know, why this space character throws an error only if image size is less than 200x200, if image size is bigger then scaling works fine.
Thanks for your time, help and support.
It is not the space that is the issue. It is whether your image is larger or smaller than 200 pixels. Read the section on -resize at
http://www.imagemagick.org/script/comma ... php#resize
The > character implies that you only want to avoid processing if smaller than that size. If your image is larger then 200x200 without the > will be processed anyway as that is a valid option. I guess it is smart enough to ignore the > with the space as 200x200 by itself is valid. But if you use 200x200> and your image is smaller then that knows not to process it. But if you use 200x200 it will process it whether it is smaller or larger. Not sure I am making sense. But the bottom line is that any qualifier like >,^,%, etc must be part of the command and not separated from it by a space. It must all be one string of characters without spaces.
Re: Image resizing :: another problem
Posted: 2008-11-03T16:18:03-07:00
by anthony
Fred answered your first problem...
The spaces cause the shell (which is executing your command) to break up the argument into two separate arguments. It also see the '>' character as having special meaning.
Your second...
sim123 wrote:I get an error saying
convert: option requires an argument `-thumbnail'.
Is caused by you having a new line instead of space, or not putting a backslash before the line feed.
As such you command stopped at '-thumbnail' which it took to be the name of the output file!
You also probably had an error about 100x100 not being executable
with the redirections causing the shell to create two empty files.
Basically be a little more careful, and see if you can get a book on basic UNIX shell handling.
Re: Image resizing :: another problem
Posted: 2008-11-06T10:27:56-07:00
by sim123
Thank you all for clarification. I would keep this in mind for future.