I
I
Ilya Korablev2015-04-24 20:42:24
PHP
Ilya Korablev, 2015-04-24 20:42:24

How to merge multiple images?

There is a mini-application where the user enters the group id and the number of group avatars to receive.
Here is the code:
index.php

<form action="group-count.php" method="POST">
  <input type="text" name="id"/><br/>
  <input type="number" min="10" name="count" max="1000" placeholder="Участники" requered/><br/>
  <input type="submit"/>
</form>

Handler. group-count.php
<?php
  array($_POST);	
  foreach($_POST as $k => $v)
  $$k = $v;
  
  $fields = "photo_50";
  
  
  $group = json_decode(file_get_contents("http://api.vk.com/method/groups.getMembers?group_id=$id&fields=$fields&count=$count"), true);
    foreach ($group['response']['users'] as $user) {
      echo "<img src=\"".$user['photo_50']."\"/>";
  }
?>

And now the task that I do not know how to implement. How to merge all images into one?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sivabur, 2015-04-25
@sivabur

<?php
// шаблонное изображение
$dest = imagecreatefrompng('vinyl.png');

// обложка
$src = imagecreatefromjpeg('cover.jpg');

// настройка прозрачности и фильтров
imagealphablending($dest, false);
imagesavealpha($dest, true);

// объединение изображений
imagecopymerge($dest, $src, 10, 9, 0, 0, 181, 180, 100);

// сообщаем браузеру, что контент страницы будет image/png
header('Content-Type: image/png');

// отображаем изображение
imagepng($dest);

// очищаем память
imagedestroy($dest);
imagedestroy($src);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question