Article From:https://segmentfault.com/q/1010000015198605
Question:

The size of a canvas is $plat 600×300

I first dropped a picture on the right side of the canvas, 300×300.

Right side

imagecopyresampled($plat, $xxx, 300, 0, 0, 0, 300, 300, 300, 300);

After that, you want to throw the user picture to the left 300×300

Left side

imagecopyresampled($plat, $src, 0, 0, 0, 0, 300, 300, $new_w, $new_h);

The two together will be a map of 600×300
It’s no problem.

The problem is how to deal with the user’s picture?
I want to get the horizontal and vertical 300×300 position of the user uploaded graph.
And then drop it into the plat canvas

$src_w = imagesx($src);
  $src_h = imagesy($src);

  if( $src_w > $src_h){
      $new_w = $src_h;
      $new_h = $src_h;
  }else{
      $new_w = $src_w;
      $new_h = $src_w;
  }

The above measures will be slightly vertical, but there will still be errors.

But how can I find no relevant resources or practices?
It may be that I find the wrong way.
Want to ask if anyone has a solution?

Answer 0:

Xie invited, why not consider reducing the complete picture of the user to 300300,What about the left side of the picture you want to synthesize? If the picture is in the middle of 300300That part, it’s very simple, too. Assuming that the length and width of the user’s uploaded graphs are w, h, and when you use the imagecopyresampled function to put the user picture on the map you want to synthesize, the coordinates x of the original map and y are (w-300) /2, (H-300), respectively./2 can get the 300*300 of the user uploading the picture.

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *