Small problem in query: syntax error near unexpected token (

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
class3f
Posts: 6
Joined: 2013-07-22T06:41:21-07:00
Authentication code: 6789

Small problem in query: syntax error near unexpected token (

Post by class3f »

I wrote a command to create four thumbnail of the original image. I run a command in PHP using exec:

Code: Select all

convert /images/*.* 
( -clone 0--1 -strip -thumbnail "68x51^>" -background white -gravity center -extent 68x51 -quality 80 +adjoin -scene 1 -write /images/%d_68x51.jpg -delete 0--1 ) 
( -clone 0--1 -strip -thumbnail "104x78^>" -background white -gravity center -extent 104x78 -quality 80 +adjoin -scene 1 -write /images/%d_104x78.jpg -delete 0--1 ) 
( -clone 0--1 -strip -thumbnail "360x270^>" -background white -gravity center -extent 360x270 -quality 80 +adjoin -scene 1 -write /images/%d_360x270.jpg -delete 0--1 ) 
-strip -thumbnail "1024x768>" -quality 80 +adjoin -scene 1 /images/%d_1024x768.jpg
It seems that is fine, but unfortunately I get the message:

Code: Select all

-bash: syntax error near unexpected token `('
Why is this happening? what's the problem? how to fix it?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Small problem in query: syntax error near unexpected tok

Post by snibgo »

I'm not a bash or PHP expert, but I think you need to tell it this is a single command, not a number of commands. For a bash script, you need a "\" character at the end of each line except the last.

You realise, I suppose, that if you successfully run the command twice, you will get a load of weird images in the same directory.
snibgo's IM pages: im.snibgo.com
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Small problem in query: syntax error near unexpected tok

Post by Bonzo »

On Linux you need to escape the ( ) with a \ so it becomes \( \)
class3f
Posts: 6
Joined: 2013-07-22T06:41:21-07:00
Authentication code: 6789

Re: Small problem in query: syntax error near unexpected tok

Post by class3f »

Thanks for your help, the server made ​​a request. I have another question: Why the query is not removed the original image? I have four thumbnails and full size image...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Small problem in query: syntax error near unexpected tok

Post by fmw42 »

You did not tell it to delete the originals only the cloned copies of the original. Add -delete 0--2 (I think) before the output or before -scene 1. That way you save the output and delete all the original input images.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Small problem in query: syntax error near unexpected tok

Post by snibgo »

class3f may not realise that "-delete" removes images from convert's internal list. It does not delete files.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Small problem in query: syntax error near unexpected tok

Post by fmw42 »

snibgo wrote:class3f may not realise that "-delete" removes images from convert's internal list. It does not delete files.

Yes, by delete, I assume he meant does not write them to output. I presume he did not mean delete from the OS directory.
Post Reply