The following code works on my laptop but doesn\'t work on remote server:
I think you might have problems with filepath. Check if pathinfo returns valid extension and add after $filename declaration something to check if it exists and is readable
if(!is_file($file) || !is_readable($file)){ die('Readable file not found');}
Changed the line:
imagecopy($image, $mask, 0, 0, 0, 0, $newwidth, $newheight);
to:
imagecopymerge($image, $mask, 0, 0, 0, 0, $newwidth, $newheight,100);
I think a basic reading of how to debug http://blog.regehr.org/archives/199 would be useful to you, and help you to solve your problem