คือมีภาพต้นฉบับหนึ่งภาพเป็นพื้นสีวางขนาด 500x500pixels มีไฟล์ สมมุติชื่อ wallpaper.jpg
ต้องการนำข้อความใส่ลงไปในภาพนี้เช่น
"สวัสดี ประเทศไทย
สยามเมืองยิ้ม"
หมายเหตุ คำว่า สวัสดี เป็นตัวสีแดง ใหญ่กว่าคำว่าประเทศไทย ซึ่งมีสีน้ำเงิน และบรรทัดต่อมาเป็นคำว่า สยามเมืองยิ้ม สีเขียว
ไม่ทราบเขียน php ยังไง ทราบมาว่าใช้ pd2 แต่สามารถปรับขนาดและสีได้หรือไม่ครับ
และถ้าเขียนข้อความผ่านฟอร์มโดยแต่งฟอร์น แต่งข้อความและให้อัพลงภาพเลยได้มั้ยคับ
ขอคำแนะนำทีครับ
ขอบคุณครับ
:wanwan017:
ไม่ทราบ ว่าทำ html เป็นใหมครับ สมุติว่าทำเป็นนะครับ
php ต้องเข้าใจก่อน ว่า *.php ใช้เพื่อ เอกสาร การเขียน โปรแกรม php ไม่ใช่การจับแปะ หรือ Drag & Drop (หลักการเขีบนโปรแกรมต้องไปอ่านเอง)
ฉะนั้นส่ิงเจ้าของกระทู้พูด การตกแต่งมันจะเป็นส่วน ของ html & CSS จะเป็น static ถ้าอยากให้เป็น Dynamic ต้องพึงหลักการเขียนโปรแกรม เพิ่มครับ
Example
<?php
echo "Hello";
print("<img src="imag.jpg" />");
?>
ลองศึกษาดูครับ http://www.thaicreate.com/php/forum/027311.html
ส่วนเรื่อง Form มันจะเกี่ยวข้องกับ Database ทันทีฉะนั้น
หากต้องการแค่โค๊ด ให้ หนีไป ที่ Plugin ของ CMS ที่ใช้ หากต้องการศึกษา ต้องศึกษา php เบื้องต้นไประดับนึงแล้ว ไปศึกศา mysql เป็น data base ตัวอย่างฟรี และง่ายที่สุด
<?php
$font = 'font/xxx.ttf'; // ที่เก็บฟอนต์ที่รองรับภาษาไทย
$text1 = 'สวัสดีครับ';
$text2 = 'มาสด้า3';
$image1 = imagecreatefromjpeg('mazda3.jpg');
$font_color1 = imagecolorallocate($image1, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255) ); // สุ่มสี font
$font_color2 = imagecolorallocate($image1, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255) ); // สุ่มสี font
imagettftext($image1, 50, 0, 600, 100, $font_color1, $font, $text1); // ใส่ข้อความ1ลงไป กำหนดตำแหน่ง
imagettftext($image1, 50, 0, 700, 200, $font_color2, $font, $text2); // ใส่ข้อความ2ลงไป กำหนดตำแหน่ง
header('Content-type: image/jpeg');
imagejpeg($image1);
imagedestroy($image1);
?>
อย่าลืมเซฟเป็น utf-8 ด้วย
ตัวอย่าง
(http://www.uppic.org/image-D25C_526C8442.jpg)
ผมว่าใช้ JQuery ช่วยอาจจะช่วยให้ง่ายขึ้นได้ครับ (เรื่องสีกับ Font ปรับเอาจาก CSS นะครับ) :wanwan019:
http://jquerydemo.com/animate-background-image.aspx
ขอบคุณทุกท่านครับ ตอนน้ผมเขียนได้แล้ว แต่ติดปัญหาตรงที่
ต้องการข้อความอยู่ตรงกลางว่า
"Welcome to Thailand
Thailand of Smile
Thank you for your visit"
ต้องเขียนเพิ่มตรงไหนครับ (จาก code ด้านล่าง)
และถ้ากำหนดตัวแปรเป็น
$String = "Welcome to Thailand
Thailand of Smile
Thank you for your visit"
บรรทุดก็ห่างเยอะมาก ต้องเขียนยังไงครับ รบกวนทีนะครับ
:wanwan017:
<?php
$height = 464;
$width = 464;
$fontsize = 50;
if (!isset($String))
$String = "Welcome to Thailand";
$im = ImageCreateFromJpeg("images/wall.jpg"); // Path Images
$blue = imagecolorallocate($im,0,0,255);
$green = imagecolorallocate($im,0,255,0);
$myfont = $_POST[fonts];
$font = "ANGORF.TTF";
$textwidth = $width;
while (1){
$box = imageTTFbbox( $fontsize, 0, $font, $String );
$textwidth = abs( $box[2] );
$textbodyheight = (abs($box[7]))-2;
if ( $textwidth < $width - 20 )
break;
$fontsize--;
}
$Xcenter = (int)($width/2 );
$Ycenter = (int)($height/2 );
imageTTFtext($im, $fontsize, 0,(int) ($Xcenter-($textwidth/2)),(int)($Ycenter+(($textbodyheight)/2) ), $blue, $font, $String );
imagegif($im,"images/img.jpg");
echo "<img src=images/img.jpg>";
?>
<?php
$font_name = 'font/xxxx.ttf'; // ที่เก็บฟอนต์ที่รองรับภาษาไทย
$text1 = 'สวัสดีครับ';
$text2 = 'มาสด้า3';
$source = 'xxxxx.jpg';
$image1 = imagecreatefromjpeg($source);
$size = getimagesize($source);
$w = $size[0];//ความกว้างของรูป
$h = $size[1];//ความสูงของรูป
$font_size = 20;
$bbox1 = imagettfbbox($font_size, 0, $font_name, $text1);
$bbox2 = imagettfbbox($font_size, 0, $font_name, $text2);
$text1_w = $bbox1[4];//หาความกว้างของ text1
$text2_w = $bbox2[4];//หาความกว้างของ text2
$post1 = ($w/2) - ($text1_w/2);//ตำแหน่งที่จะแสดงข้อความกึ่งกลาง คือ (w ของรูป /2) แล้วลบด้วย text1_w/2
$post2 = ($w/2) - ($text2_w/2);
$font_color1 = imagecolorallocate($image1, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255) ); // สุ่มสี font
$font_color2 = imagecolorallocate($image1, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255) ); // สุ่มสี font
imagettftext($image1, $font_size, 0, $post1, $h/2, $font_color1, $font_name, $text1); // ใส่ข้อความ1ลงไป กำหนดตำแหน่ง
imagettftext($image1, $font_size, 0, $post2, $h/3, $font_color2, $font_name, $text2); // ใส่ข้อความ2ลงไป กำหนดตำแหน่ง
header('Content-type: image/jpeg');
imagejpeg($image1);
imagedestroy($image1);
?>