2015-01-16 28 views
0

即时建立一个网站indianskincare.co.in这是出来我想要的。问题是我想将每个产品的所有文本都转换为图片,因为我的客户希望文本不会被轻易复制。通过调用图像源中的PHP和php中的相关代码,我看到了如何使用PHP来完成此操作。文字与图片与MySQL信息

它工作在正常文本奇妙,但是当我包括MySQL行或任何复杂的代码它显示一个破碎的图像。

这个作品显示时间,文本

Header("Content-type: image/png"); 


$image = imagecreate(320,130); 
$date = date ("F dS Y h:i a"); 
$ip = "ip"; 
$fullip = "Your IP address is $ip."; 
$black = ImageColorAllocate($image,0,0,0); 
$red = ImageColorAllocate($image,204,0,0); 
$white = ImageColorAllocate($image,255,255,255); 
ImageFilledRectangle($image,0,0,320,130,$white); 
ImageString($image, 14, 0, 0, "$fullip", $red); 
ImageString($image, 12, 0, 24, "Time is $date", $black); 
ImagePNG($image); 
ImageDestroy($image); 

我尝试添加的一个变量之间我的MySQL的代码(我没想到它会之间关系),否则完美的作品另一页上,但可以似乎没有把文字变成图片。

MySQL代码

if(isset($_GET['id'])) 
{ 
$id=$_GET['id']; 
$qry=mysql_query("SELECT * FROM Product WHERE id='$id'", $con); 
if(!$qry) 
{ 
die("Query Failed: ". mysql_error()); 
} 

       /* Fetching data from the field "title" */ 
while($row=mysql_fetch_array($qry)) 
{ 
echo "<div style='overflow-x:hidden;width:20%;margin:0.5em;text-align:center;float:left;'>"; 
echo "<h3>".$row['name']."</h3>"; 
echo "<img style='width:100%;margin:0;' src='".$row['image']."' /><br>"; 
echo "<h1><img style='height:4%;' src='images/rs.png' />".$row['price']."</h1><br><a href='product.php?cat=".$row['short']."'>Back</a><br>"; 
echo "</div><div style='width:50%;float:left;'>"; 
echo "<h5 style='font-weight:normal;'>".$row['description']."</h5><br>"; 

所以我的问题是如何修改从MySQL阵列文成图像。

PS:我知道MySQL的功能已被淘汰不理想,但香港专业教育学院已经在使用这个工作的网站,我将无法修改它使用其他方法

+0

它高兴地知道有人可以降低投票的这个没有任何意见,为什么 –

+0

这不是你的问题的答案,但是你的客户意识到这将导致所有问题?您将遇到与浏览器兼容性有关的重大问题,您将确保没有任何人使用屏幕阅读器可以使用您的网站,并且维护内容将会更加困难。有足够动机的人仍然可以通过一些额外的工作来获取内容。 – andrewsi

+0

我没有downvoye(但),但它可能是因为你只显示了两个无关的代码块。尝试显示您尝试的实际代码。但是,如果你回应HTML,那么你已经成为一个失败者。看看工作映像代码是如何工作的(提示 - 'ImageString'接受一个字符串,并且没有回声)并从那里开始。 – Steve

回答

1

时间以前,我使用这个类 - 它完美的作品:

http://image.intervention.io/

介入影像需要以下组件才能正常工作。

PHP >= 5.3 
Fileinfo Extension 

并且以下图像库之一。

GD Library (>=2.0) … or … 
Imagick PHP extension (>=6.5.7) 

良好的开端是安装作曲: https://packagist.org/

有了你可以很容易地安装PHP组件/模块的几乎所有问题的作曲家。从页面(如何将文本转换为图像)

// create Image from file 
$img = Image::make('public/foo.jpg'); 

// write text 
$img->text('The quick brown fox jumps over the lazy dog.'); 

// write text at position 
$img->text('The quick brown fox jumps over the lazy dog.', 120, 100); 

// use callback to define details 
$img->text('foo', 0, 0, function($font) { 
    $font->file('foo/bar.ttf'); 
    $font->size(24); 
    $font->color('#fdf6e3'); 
    $font->align('center'); 
    $font->valign('top'); 
    $font->angle(45); 
}); 

// draw transparent text 
$img->text('foo', 0, 0, function($font) { 
    $font->color(array(255, 255, 255, 0.5)) 
}); 

例子那么你的代码的例子可以(如果介入影像类工作):

$result = array(); 

while($row=mysql_fetch_array($qry)) 
{ 
    $result[] = array(
     'name' => convertToImage($row['name'], $row['id'].'_name'), 
     'price' => convertToImage($row['price'], $row['id'].'_price') 
    ) 
} 

function convertToImage($text, $name) { 
    $img = Image::make('images/transparent.png'); 
    $img->text($text); 
    $img->save('images/'.$name.'.png'); 
    return '<img src="images/'.$name.'.png">'; 
} 
?> 
+0

那么如何整合mysql。我在这里的主要问题 –

+0

看看我的编辑 – goldlife

+0

即时通讯标记你的答案是正确的,但基本上安德鲁已经给出了一个理由不这样做。谢谢。 –