Scaling a watermark to fit parent image
===

My photo sizes vary, they are either landscape, portrait or square, and I need to make a watermark the best fit for each photo - so I need to resize just the width of the watermark (without Imagick), as it's a long rectangle shape, so height doesn't matter.

I found the PHP function, `imagecopyresized`, but I'll be honest, I can't work out what parameters are needed for my situation, even after looking at PHP documentation! I'm also not sure if after using imagecopyresized, the rest of my function will work where it gets the watermark width and height.

Can somebody help me get over the finish line. This is how far I got, all it needs is the right parameters added to the imagecopyresized part.

    <?
    
    header('content-type: image/jpeg');
    
    $image = imagecreatefromjpeg('https://.....jpg');
    $imageSize = getimagesize('https://.....jpg');
    
    $newWatermarkWidth = $imageSize[0]-50; // width of image minus 50px
    $watermark = imagecreatefrompng('watermark.png');
    
    // resize watermark to newWatermarkWidth here with imagecopyresize
    $watermark = imagecopyresized(?,?,?,?);
    
    $watermark_width = imagesx($watermark);
    $watermark_height = imagesy($watermark);
    
    $dest_x = ($imageSize[0]/2) - ($watermark_width/2) ;
    $dest_y = ($imageSize[1]/2) - ($watermark_height/2);
    
    imagecopy($image, $watermark, round($dest_x,0), round($dest_y,0), 0, 0, $watermark_width, $watermark_height);
    imagejpeg($image);
    imagedestroy($image);
    imagedestroy($watermark);
    
    ?>