One way to do this is to use phpThumb.
Base link here: http://phpthumb.sourceforge.net/demo/demo/phpThumb.demo.demo.php#x31
If you create a new image on the fly, it will be so simple:
<img src="../phpThumb.php?src=path/to/image/image.jp&fltr[]=mask|path/to/mask/mask.png&f=png" alt="">
For output to png.
, , , phpThumb, :
:
...
require_once('phpThumb/phpthumb.class.php');
$uploaddir = $_SERVER['DOCUMENT_ROOT'] . $destination;
$uploadfile = $uploaddir . $file;
$phpThumb = new phpThumb();
$phpThumb->setSourceFilename($uploadfile);
$phpThumb->setParameter('w', 360);
$phpThumb->setParameter('h', 470);
$phpThumb->setParameter('fltr[]', 'mask|path/to/mask/mask.png');
$phpThumb->setParameter('f', 'png');
$outputdir = $_SERVER['DOCUMENT_ROOT'] . $destination;
$output_filename = $outputdir . "masked" . $file;
$phpThumb->setParameter('config_allow_src_above_docroot', true);
if ($phpThumb->GenerateThumbnail()) {
if ($phpThumb->RenderToFile($output_filename)) {
...