Avatar of projects

asked on 

Merging images to the same width

The following code merges a blob image from mysql with a logo image to be shared on social sites.
The problem is that the blob always looks fuzzy, the logo looks crisp but is often wider than the blob image. This seems to happen randomly and makes no sense since both images are always the same width.

Wondering if someone could offer a solution which would merge both at the optimum social site (FB in this case) size, making them the same width and both crisp. No idea if this is something which can be asked, done in a question like this but thought I'd ask since my dev isn't around for a couple days and I need this fixed.

$img = $image_data_row['image'];

$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$img = base64_decode($img);

$image1 = imagecreatefromstring($img);
$image2 = imagecreatefrompng('logo.png'); //800 x 150

$merged_image = imagecreatetruecolor(800, 426);
imagealphablending($merged_image, false);
imagesavealpha($merged_image, true);

imagecopy($merged_image, $image1, 0, 150, 0, 0, 800, 276);
imagecopy($merged_image, $image2, 0, 0, 0, 0, 800, 150);

header('Content-Type: image/png');

Open in new window

Images and PhotosLinuxPHP

Avatar of undefined
Last Comment

8/22/2022 - Mon