Is it possible to use imagecopyresampled and imagecopymerge at the same time?

Asked

Viewed 99 times

0

I was able to set the fixed size for the image (500x500) now I wanted to know if you have to take this image already defined and put another one on top with imagecopymerge?

<?php

$img = $_POST['img'];
$user = imagecreatefromjpeg($img);
$mask = imagecreatefromgif('imgs/logo.gif');
$width = 500;
$height = 500;
$image_p = imagecreatetruecolor($width, $height);
list($width_orig, $height_orig) = getimagesize($img);
$ratio_orig = $width_orig/$height_orig;
if ($width/$height > $ratio_orig) {
      $width = $height*$ratio_orig;
   } else {
      $height = $width/$ratio_orig;
   }
$imagem = imagecopymerge($user, $mask, 0,0,0,0,500,500,50);
imagecopyresampled($image_p, $user, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
header('Content-Type: image/png');
imagepng($image_p);
?>

1 answer

1


Yeah, there’s a way.

Let’s say you have this image of yourself as a result of imagecopyresampled in the variable $minhaImagem, you can use it $dst_im of imagecopymerge

imagecopymerge ( $minhaImagem , resource $src_im , int $dst_x , int $dst_y , int $src_x , int $src_y , int $src_w , int $src_h , int $pct )

Remember that to work with images should be used

$_FILES['img']['tmp_name']

Instead of

$_POST['img']

And your form should be with the attribute enctype="multipart/form-data"

More information on php.net

  • So, I tried but gives that broken image icon, I do not know if I’m calling the right image in "imagejpeg(); I will post the code to facilitate...

  • This puts the code, additionally the broken image icon appears in the front or back image?

  • No image appears when I add imagecopymerge()

  • @Bruno take a look at my answer, probably the problem is in $_POST['img']; which should be $_FILES['img']['tmp_name']

  • I don’t think so, because the [$_POST['img]] comes from a link that the user type in the input text, being the jpg image, not uploading anything on the server...

  • This link is a relative link /img/teste.jpg or complete http://teste.com/imagem.jpg

  • Complete... I will edit the code(again) I made a form that overlaps the two image and after a resize to 500px maaas, I wanted to give the resize of 500px and then put the image over, so the image would be in the center, for example this flag that Facebook put up from France... you know? I’m trying to do in php for study...

  • Nothing yet....?

  • test imagecopyresampled($image_p, $user, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);&#xA;imagecopymerge($image_p, $mask, 0,0,0,0,500,500,50);

  • It worked lol worth Alan :D

Show 5 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.