 |
|
เขียนอักษรลงภาพโดยใช้ php ได้ แต่พอดึงข้อมูลจาก mysql แล้วเกิดปัญหาครับ |
|
 |
|
|
 |
 |
|
เขียนอักษรลงภาพโดยใช้ php ได้ แต่พอดึงข้อมูลจาก mysql แล้วเกิดปัญหาครับ
ผมได้ลองใช้
<?php
$string = "test"; // string
$img_file="test4.jpg";
if (function_exists("imagejpeg")) {
header("Content-type: image/jpeg");
$im = imagecreatefromjpeg("$img_file"); // file type
// set color in hexadecimal way
//$color = ImageColorAllocate($im, 0x00, 0x00, 0x00); // set black color by hexadecimal way
$color = ImageColorAllocate($im, 0xFF, 0xFF, 0xFF); // set color by hexadecimal way
$px = (imagesx($im) - 1 * strlen($string)) / 100; // position of string
imagestring($im, 100, $px, 10, $string, $color); // position of string
imagejpeg($im);
imagedestroy($im);
}
else { die("Not support this file"); }
?>
แล้วภาพก็สามารถปรากฏเป็นดัง
http://members.thai.net/thaiwebsite/test4.jpg
แต่ว่าพอผมจะดึงข้อมูลจากฐานข้อมูล Mysql
แล้วลองแก้ไข source code เป็น
<?php
$host = "localhost";
$user = "test"; // ใส่ user name
$passwd = "test"; // ใส่ password
$dbname = "test"; // ชื่อ database
mysql_connect($host,$user,$passwd);
$sql = "select * from $pym_data where No='$No'";
$result = mysql_db_query($dbname,$sql);
$NRow = mysql_num_rows($result);
$row = mysql_fetch_array($result);
// กำหนดค่าตัวแปร เพื่อนำไปแสดง
$nphoto = $row["nphoto"]; //ตัวนี้จะเก็บ file .jpg ไว้ เช่น test.jpg ครับ
$pageviewdata = $row["pageview"];
//add คนดู
mysql_query("update $pym_data set pageview=pageview+1 where No=$No");
$string = "test"; // string
$img_file="$nphoto";
if (function_exists("imagejpeg")) {
header("Content-type: image/jpeg");
$im = imagecreatefromjpeg("$img_file"); // file type
// set color in hexadecimal way
//$color = ImageColorAllocate($im, 0x00, 0x00, 0x00); // set black color by hexadecimal way
$color = ImageColorAllocate($im, 0xFF, 0xFF, 0xFF); // set color by hexadecimal way
$px = (imagesx($im) - 1 * strlen($string)) / 100; // position of string
imagestring($im, 100, $px, 10, $string, $color); // position of string
imagejpeg($im);
imagedestroy($im);
}
else { die("Not support this file"); }
?>
ปรากฏว่ามันไม่แสดงผลอออกอะไรมาเลยครับ
รบกวนท่านผู้รู้แนะนำด้วยนะครับ
Tag : - - - -
|
|
 |
 |
 |
 |
Date :
1 มิ.ย. 2549 16:49:03 |
By :
pyayam |
View :
2342 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?
echo "<img src=MyResize/mygirl.png>";
$string = "Narak Girl By ThaiCreate.Com"; // String
$im = ImageCreateFromJpeg("mygirl.jpg"); // Path Images
$color = ImageColorAllocate($im, 255, 0, 0); // Text Color
$pxX = (Imagesx($im) - 6.5 * strlen($string))/2; // X
$pxY = Imagesy($im)- 20; // Y
ImageString($im, 200, $pxX, $pxY, $string, $color);
imagePng($im,"MyResize/mygirl.png");
ImageDestroy($im);
?>
Go to : PHP Write text in Image
|
 |
 |
 |
 |
Date :
2011-08-01 09:35:54 |
By :
thaicreate |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|