/**
* @param UploadedFile the file you want saved to the disk
* @param filename including the dir
*/
function saveCreatedProductArtwork($created_artwork,$template_file,$filename = null){
$error = 0;
if (UploadedFile::isJpeg($created_artwork->getTmpName())){
if ($filename == null){
$filename = rand(1000000,9999999).'.jpg';
while(file_exists(CREATED_ARTWORK_TEMP_DIR.'/'.$filename)){
$filename = rand(1000000,9999999).'.jpg';
}
}
$f = CREATED_ARTWORK_TEMP_DIR.'/'.$filename;
if (is_uploaded_file($created_artwork->getTmpName())){
if (!move_uploaded_file($created_artwork->getTmpName(),$f)) throw new Exception('File not moved.');
}
else {
if (!rename($created_artwork->getName(),$f)) throw new Exception('File not moved.');
}
}
else throw new Exception('Image is not a jpg');
if (!imagecopy(imagecreatefrompng(ARTWORK_TEMPLATE_DIR.'/'.$template_file),imagecreatefromjpeg($f),0,0,0,0,0,0)) throw new Exception('Not merging.');
if (!rename($f,CREATED_ARTWORK_FINAL_DIR.'/'.$filename)) throw new Exception('Couldn\'t move the temporary file');
return $filename;
}