Perfect in command line but problems in my php script
Its Ghostscript that is failing in your PHP script. Your PHP environment is different than your command line environment. One thing to look for is two different versions of Ghostscript (gs) installed on your system. Another is permission problems. You could try running Ghostscript in your PHP script without ImageMaigck and see if that fails. Once you get Ghostscript working within a PHP script, ImageMagick should then work.