Поместите изображение в другое изображение с помощью PHP

У меня есть изображение, на котором текст динамически генерируется через php-форму. У меня есть местоположение изображения логотипа, сохраненного в переменной из базы данных mysql. Есть ли способ сделать это изображение и применить его к фиксированной позиции на изображении? В случае необходимости, он должен быть изменен по размеру меньше, чтобы соответствовать этой области изображения.

У меня уже есть сценарий, который выглядит так:

$img = imagecreatefromjpeg('coupon/coupontemplate.jpg'); $textColor = imagecolorallocate($img, 0, 0, 0); // black text //Write first the coupon title imagefttext($img, 16, 0, 20, 34, $textColor, 'coupon/arialbd.ttf', $title); //Then write the coupon description imagettftextbox($img, 13, 0, 20, 45, $textColor, 'coupon/arial.ttf', $description, 440); //If the checkbox to include logo is checked... if ($_POST['clogo'] == 'y') { $logo = $row['imagecompany']; $logo_file = "../directory/memberimages/$logo"; $logo_file_type = getimagesize($logo_file); if ($logo_file_type['mime'] == 'image/jpg') { $logoImage = imagecreatefromjpeg($logo_file); } else if ($logo_file_type['mime'] == 'image/gif') { $logoImage = imagecreatefromgif($logo_file); } else if ($logo_file_type['mime'] == 'image/png') { $logoImage = imagecreatefrompng($logo_file); } } // Output image to the browser //header('Content-Type: image/jpeg'); //imagejpeg($img); // Or save to file imagejpeg($img, 'my-text.jpg'); imagedestroy($img); } //} 

У кого-нибудь есть идеи, как это сделать – получить изображение из указанного места и поместить его на другое изображение? Благодаря!

Я думаю, что вы ищете либо imagecopyresampled (), либо imagecopyresized () .

Слияние изображений можно сделать примерно так: ссылка

 <?php # If you don't know the type of image you are using as your originals. $image = imagecreatefromstring(file_get_contents($your_original_image); $frame = imagecreatefromstring(file_get_contents($your_frame_image)); # If you know your originals are of type PNG. $image = imagecreatefrompng($your_original_image); $frame = imagecreatefrompng($your_frame_image); imagecopymerge($image, $frame, 0, 0, 0, 0, 50, 50, 100); # Save the image to a file imagepng($image, '/path/to/save/image.png'); # Output straight to the browser. imagepng($image); 

Вы можете использовать функцию imagecopy . Быстрый поиск показал этот пост, который, возможно, поможет вам.

http://forums.bit-tech.net/showthread.php?t=117270

Функция, которую вы хотите, – это imagecopy:

bool imagecopy (ресурс $ dst_im, ресурс $ src_im, int $ dst_x, int $ dst_y, int $ src_x, int $ src_y, int $ src_w, int $ src_h)

http://php.net/manual/en/function.imagecopy.php