2016-10-13 10 views
0

私は2つの異なる画像を持っています.1つはローカルマシンにあり、もう1つはウェブにあります。私はこれらの2つのイメージをマージしたい、私はすべてがあるが、私の問題は、これらの2つのイメージは同じ幅と高さではありません。私のローカルイメージはマスクであり、オンラインイメージはローカルに適合する必要があります。ローカル画像のサイズは400x400です。固定サイズに切り抜くことで画像を使用することは可能ですか

問題:オンライン画像の寸法がローカル画像よりも小さい場合は、画像が実際のサイズになり、マスク画像に収まりません。

ここで、これらのイメージをお互いに適合させるにはどうすればよいですか?ですから、これを必要とする

//define the width and height of our images 
define("WIDTH", 400); 
define("HEIGHT", 400); 

$dest_image = imagecreatetruecolor(WIDTH, HEIGHT); 

//make sure the transparency information is saved 
imagesavealpha($dest_image, true); 

//create a fully transparent background (127 means fully transparent) 
$trans_background = imagecolorallocatealpha($dest_image, 0, 0, 0, 127); 

//fill the image with a transparent background 
imagefill($dest_image, 0, 0, $trans_background); 

//take create image resources out of the 3 pngs we want to merge into destination image 
$a = imagecreatefrompng('https://rickwgrundy.files.wordpress.com/2014/01/pt509_stick_figure_podium_speaking-348x370.png'); 
$b = imagecreatefrompng('400x400.png'); 

//copy each png file on top of the destination (result) png 
imagecopy($dest_image, $a, 0, 0, 0, 0, WIDTH, HEIGHT); 
imagecopy($dest_image, $b, 0, 0, 0, 0, WIDTH, HEIGHT); 

//send the appropriate headers and save the image in the given link name 
header('Content-Type: image/png'); 
imagepng($dest_image, "result.png", 9); 

//destroy all the image resources to free up memory 
imagedestroy($a); 
imagedestroy($b); 
imagedestroy($dest_image); 
+0

uがuはここ –

+0

は私が何を提供できるすべてです欲しいもの実際にこの上でより詳細な情報を与えることができます。私は他に何も持っていません。 – Mysterious

+0

オンライン画像のローカル画像をマージしますか? –

答えて

0

代わりの imagecopy($dest_image, $a, 0, 0, 0, 0, WIDTH, HEIGHT);あなたはimagecopyresizedhttp://php.net/manual/en/function.imagecopyresized.php

を使用して画像をコピーして、サイズを変更する必要があります - どのような私がしよう[ウェブから収集]さ

My output Image

imagecopy($dest_image, $a, 0, 0, 0, 0, WIDTH, HEIGHT);を次のように置き換えます。

$image_current_width = imagesx($a); 
$image_current_height = imagesy($a); 
imagecopyresized($dest_image, $a, 0, 0, 0, 0, WIDTH, HEIGHT, $image_current_width , $image_current_height); 

イメージをコピーしている間にイメージのサイズが変更されます。

+0

さて、イメージは次のようになります。[http://imgur.com/](http://imgur.com/a/q9Crr) – Mysterious

+0

ちょっと、私は 'imagecopyresized(... )。どうもありがとう。 – Mysterious

0

はいウェブ画像は400x400ではなく可能ですか?あなたのウェブイメージ348X370そう。あなたのローカルイメージ348X370は100%正常に動作しています。私は自分のローカルイメージベースをあなたのウェブイメージで試してから作業しています。 my image and your web image

と私のコードここ

function imagecopymerge_alpha($dst_im, $src_im, $dst_x, $dst_y, $src_x,$src_y, $src_w, $src_h, $pct) 
{ 
$cut = imagecreatetruecolor($src_w, $src_h); 
imagecopy($cut, $dst_im, 0, 0, $dst_x, $dst_y, $src_w, $src_h); 
imagecopy($cut, $src_im, 0, 0, $src_x, $src_y, $src_w, $src_h); 
imagecopymerge($dst_im, $cut, $dst_x, $dst_y, 0, 0, $src_w, $src_h, $pct); 
} 

$image1 = imagecreatefrompng('https://rickwgrundy.files.wordpress.com/2014/01/pt509_stick_figure_podium_speaking-348x370.png'); //348 x 370 
$image2 = imagecreatefrompng('b.png'); //348 x 370 
imagealphablending($image1, false); 
imagesavealpha($image1, true); 

imagecopymerge_alpha($image1, $image2, 10, 9, 0, 0, 348, 370, 100); 
header('Content-Type: image/png'); 

imagepng($image1); 
+0

約22分前の回答で、私はあなたの時間に感謝しています。 – Mysterious

関連する問題