|
 |
|
ซ้อนภาพ แล้วภาพไม่โปร่งใส่ ต้องแก้ไขไงครับ ช่วยหน่อยครับ |
|
 |
|
|
 |
 |
|
พอดีผมต้องการนำLOGO ที่ได้จากการอัพโหลดมาซ้อนทับรูปภาพเพื่อสรา้งภาพใหม่ขึ้นมาครับ แต่ ปรากฏว่า ภาพที่สร้างออกมาตรงส่วนที่โปร่งใส่ กลับกลายเป็นสีดำ ต้องแก้ไข ไงครับ รบกวนพี่ช่วยดูให้ทีคับ จากโค๊คด้านล่าง
Code (PHP)
header("Content-type: image/png");
$images = imagecreate(25,25);
$color = imagecolorallocate($images,$rgb[0],$rgb[1],$rgb[2]);
$photo = imagecolorallocate($images,$rgb[0],$rgb[1],$rgb[2]);
imagerectangle($images, 0, 0, 299, 199, $photo);
imagepng($images,"upload_images/".$CATEGORTES.".png");
imagedestroy($images);
header('Content-Type: image/png');// ส่งออกเป็นไฟล์ภาพ png
$bg_im = imagecreatefrompng("upload_images/".$CATEGORTES.".png"); // ตำแหน่งไฟล์รูปภาพสำหรับพื้นหลัง
$fg_im = "upload_images/".$images_name; // ตำแหน่งไฟล์รูปภาพสำหรับวางทับด้านบน
list($width, $height) = getimagesize($fg_im); // หาขนาดของไฟล์สำหรับวางทับด้านบน
$newwidth =20; /// คำกว้าง ใหม่ ในที่นี้มีการกำหนดตายตัว ถ้าภาพไม่ได้สัดส่วน อาจบิดเบี้ยวได้
$newheight =20; // ค่าความสูงใหม่ ในที่นี้มีการกำหนดตายตัว ถ้
// สร้างรูปภาพตามค่าใหม่ สำหรับรูปภาพวางทับด้านบน
$thumb = imagecreatetruecolor($newwidth, $newheight);
// โดยสร้างจากไฟล์ ต้นฉบับ
$source = imagecreatefrompng($fg_im);
imagealphablending($bg_im, true); // กำหนดโปร่งใส่ภาพพื้นหลัง
imagesavealpha($bg_im, true); // กำหนดโปร่งใส่ภาพพื้นหลัง
// เริ่มสร้างรูปภาพตามค่าใหม่ สำหรับรูปภาพวางทับด้านบน ตามขนาดที่กำหนด
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// ทำการรวมภาพ 2 ภาพ
// imagecopymerge($bg_im, $thumb, ขยับรูปด้านบน จาก x, ขยับรูปด้านบน จาก y, 0,0, $newwidth, $newheight, ค่า 0-100);
imagecopymerge($bg_im, $thumb, 3, 3, 0,0, $newwidth, $newheight, 75);
imagepng($bg_im,"upload_images/".$CATEGORTES.".png");// แสดงภาพ
//imagecreatefrompng($bg_im,"upload_images/".$CATEGORTES.".png");
$IMG = $CATEGORTES.".png";
imagedestroy($bg_im);
imagedestroy($thumb);
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2015-03-19 15:02:16 |
By :
testonline |
View :
1382 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองดูตัวอย่างการกำหนดสีสำหรับ transparent
Code (PHP)
$im = ImageCreateFromPNG($source);
$new_im = imagecreatetruecolor($new_size[0],$new_size[1]);
imagecolortransparent($new_im, imagecolorallocate($new_im, 0, 0, 0));
imagecopyresampled($new_im,$im,0,0,0,0,$new_size[0],$new_size[1],$size[0],$size[1]);
|
 |
 |
 |
 |
Date :
2015-03-19 15:15:58 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบความคิดเห็นที่ : 1 เขียนโดย : Chaidhanan เมื่อวันที่ 2015-03-19 15:15:58
รายละเอียดของการตอบ ::
ไม่ได้อ่าครับพี่ หรือว่าผมใส่ผิดตรงไหนอ่าครับ พี่ช่วยให้หน่อยดิได้ไหมครับ
Code (PHP)
header("Content-type: image/png");
$images = imagecreate(25,25);
$color = imagecolorallocate($images,$rgb[0],$rgb[1],$rgb[2]);
$photo = imagecolorallocate($images,$rgb[0],$rgb[1],$rgb[2]);
imagerectangle($images, 0, 0, 0, 0, $photo);
imagepng($images,"upload_images/".$CATEGORTES.".png");
imagedestroy($images);
header('Content-Type: image/png');// ส่งออกเป็นไฟล์ภาพ png
$bg_im = imagecreatefrompng("upload_images/".$CATEGORTES.".png"); // ตำแหน่งไฟล์รูปภาพสำหรับพื้นหลัง
$fg_im = "upload_images/".$images_name; // ตำแหน่งไฟล์รูปภาพสำหรับวางทับด้านบน
list($width, $height) = getimagesize($fg_im); // หาขนาดของไฟล์สำหรับวางทับด้านบน
$newwidth =20; /// คำกว้าง ใหม่ ในที่นี้มีการกำหนดตายตัว ถ้าภาพไม่ได้สัดส่วน อาจบิดเบี้ยวได้
$newheight =20; // ค่าความสูงใหม่ ในที่นี้มีการกำหนดตายตัว ถ้
// สร้างรูปภาพตามค่าใหม่ สำหรับรูปภาพวางทับด้านบน
$thumb = imagecreatetruecolor($newwidth, $newheight);
// โดยสร้างจากไฟล์ ต้นฉบับ
$source = imagecreatefrompng($fg_im);
imagealphablending($bg_im, true); // กำหนดโปร่งใส่ภาพพื้นหลัง
imagesavealpha($bg_im, true); // กำหนดโปร่งใส่ภาพพื้นหลัง
$im = imagecreatefrompng($source);
$new_im = imagecreatetruecolor($new_size[0],$new_size[1]);
imagecolortransparent($new_im, imagecolorallocate($new_im, 0, 0, 0));
imagecopyresampled($new_im,$im,0,0,0,0,$new_size[0],$new_size[1],$size[0],$size[1]);
// เริ่มสร้างรูปภาพตามค่าใหม่ สำหรับรูปภาพวางทับด้านบน ตามขนาดที่กำหนด
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// ทำการรวมภาพ 2 ภาพ
// imagecopymerge($bg_im, $thumb, ขยับรูปด้านบน จาก x, ขยับรูปด้านบน จาก y, 0,0, $newwidth, $newheight, ค่า 0-100);
imagecopymerge($bg_im, $thumb, 3, 3, 0,0, $newwidth, $newheight, 75);
imagepng($bg_im,"upload_images/".$CATEGORTES.".png");// แสดงภาพ
//imagecreatefrompng($bg_im,"upload_images/".$CATEGORTES.".png");
$IMG = $CATEGORTES.".png";
imagedestroy($bg_im);
imagedestroy($thumb);
|
 |
 |
 |
 |
Date :
2015-03-19 15:33:35 |
By :
testonline |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใครก็ได้ช่วยทีครับ _* _ .........................
|
 |
 |
 |
 |
Date :
2015-03-19 16:07:03 |
By :
testonline |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
บันทัด 22 ต้องใช้ ชื่อไฟล์ หรือเปล่า $source มันเป็น object image ไม่ใช่เหรอ
และก็ปรับ ตัวแปรให้เป็นของที่ต้องการด้วย เช่นขนาดรูปภาพ สี ของผมเป็นแค่ตัวอย่าง
อ่าน document แต่ละ ฟังก์ชั่นเอาครับ จะได้รู้ว่า parameter มันต้องใส่อะไร ลงไป
|
ประวัติการแก้ไข 2015-03-19 16:12:55
 |
 |
 |
 |
Date :
2015-03-19 16:09:54 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|