![]() | ![]() ![]() |
<?php
$characters = $_POST['characters'];
$fontsize= $_POST['fontsize'];
$img_type = $_POST['color'];
$bgcolor= $_POST['bgcolor'];
?>
<html>
<title>Tạo ảnh từ text</title>
<style>
body{
background:<?=$bgcolor;?>;
font-size: <?=$fontsize;?>px;
}
.bold{
color: red;
font-size: 15px;
font-weight: bold;
}
</style>
<body>
<?php
$imagesize = "150";
$index = 0;
$path = "images/";
$allowedExts = array("jpg", "jpeg", "gif", "png");
$allowedTypes = array("image/gif", "image/jpeg", "image/jpg", "image/pjpeg","image/png");
$extension = end(explode(".", $_FILES["image"]["name"]));
$newfilename = time().".".$extension;
$filename = $_FILES["image"]["name"];
$filetmp = $_FILES["image"]["tmp_name"];
$filetype = $_FILES["image"]["type"];
$filesize = $_FILES["image"]["size"];
$filesize = number_format(( $filesize / 1024 ) / 1024 , 2);
if(!$_FILES["image"]["error"]){
if (in_array($filetype,$allowedTypes) && in_array($extension, $allowedExts))
{
if(($filesize < 2)) // check if file size less than 2 mb
move_uploaded_file($filetmp,"images/" . $newfilename);
else{
echo '<span class="bold">Image is too big</span>';
exit;
}
}else{
echo '<span class="bold">Invalid image, Supported formats jpeg, png, gif</span>';
exit;
}
}
$thumb = "thumb_".$newfilename;
imagecreatethumbnail($path.$newfilename,$path.$thumb,$imagesize /2 ,$imagesize /2);
//$thumb = thumbnail_box(imagecreatefromjpeg($path.$newfilename),$path.$thumb, 210, 150);
//imagedestroy($i);
if(!file_exists($path.$thumb)) {
echo "File not found";
exit;
}
$im = imagecreatefrompng($path.$thumb);
if(!$im) echo "Cant open image";
$w = imagesx($im);
$h = imagesy($im);
for( $i = 0; $i < $h; $i++ ) {
for( $j = 0; $j < $w; $j++ ) {
//if($j%2 == 0) continue;
$rgb = imagecolorat($im, $j, $i);
$a = ($rgb >> 24) & 0xFF;
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
$pixel = $characters[$index];
if($img_type == "gray"){
$gray = round(($r + $g + $b) / 3);
//if($gray > 0x7F) $gray = 0xFF;
//$gray = 0x00;
echo "<span style='color:rgb($gray,$gray,$gray);'>$pixel</span>";
}else{
echo "<span style='color:rgb($r,$g,$b);'>$pixel</span>";
}
//echo "<div style='background:rgb($r,$g,$b);float:left;width:1px; height:1px;'>@</div>";
$index++;
if($index >= count(str_split($characters)))
$index = 0;
}
echo "<br>";
}
//unlink($path.$thumb);
unlink($path.$newfilename);
function imagecreatethumbnail($file,$output,$max_width = 150,$max_height = 150)
{
extract($_POST);
$img = imagecreatefromstring(file_get_contents($file));
list($width, $height, $type, $attr) = getimagesize($file);
if($height > $max_height || $width > $max_width)
{
if($width > $height)
{
$thumb_width = $max_width;
$thumb_height = ceil(($height * $thumb_width)/$width);
}
else
{
$thumb_height = $max_height;
$thumb_width = ceil(($width * $thumb_height)/$height);
}
} else {
$thumb_width = $width;
$thumb_height = $height;
}
$thumb_width = $thumb_width + ($thumb_width * ($fontsize / 6) );
imagesavealpha($img,true);
$thumb = imagecreatetruecolor($thumb_width,$thumb_height);
imagesavealpha($thumb,true);
imagealphablending($thumb,false);
imagecopyresampled($thumb,$img,0,0,0,0,$thumb_width,$thumb_height,$width,$height);
$return = imagepng($thumb,$output);
imagedestroy($img);
imagedestroy($thumb);
return $return;
}
?>
</body>
</html>
<?php
/*
code by Chụy Hiệp
*/
if(isset($_POST['ok']))
{
$characters = $_POST['characters'];
$fontsize= $_POST['fontsize'];
$img_type = $_POST['color'];
$bgcolor= $_POST['bgcolor'];
echo '
<html>
<title>Tạo Ảnh Từ Text By Chụy Hiệp</title>
<style>
body{
background:'.$bgcolor.';
font-size: '.$fontsize.'px;
}
.bold{
color: red;
font-size: 15px;
font-weight: bold;
}
</style>
<body>
<center>';
function imagecreatethumbnail($file,$output,$max_width = 150,$max_height = 150)
{
extract($_POST);
$img = imagecreatefromstring(file_get_contents($file));
list($width, $height, $type, $attr) = getimagesize($file);
if($height > $max_height || $width > $max_width)
{
if($width > $height)
{
$thumb_width = $max_width;
$thumb_height = ceil(($height * $thumb_width)/$width);
}
else
{
$thumb_height = $max_height;
$thumb_width = ceil(($width * $thumb_height)/$height);
}
} else {
$thumb_width = $width;
$thumb_height = $height;
}
$thumb_width = $thumb_width + ($thumb_width * ($fontsize / 6) );
imagesavealpha($img,true);
$thumb = imagecreatetruecolor($thumb_width,$thumb_height);
imagesavealpha($thumb,true);
imagealphablending($thumb,false);
imagecopyresampled($thumb,$img,0,0,0,0,$thumb_width,$thumb_height,$width,$height);
$return = imagepng($thumb,$output);
imagedestroy($img);
imagedestroy($thumb);
return $return;
}
$imagesize = "150";
$index = 0;
$path = "images/";
$allowedExts = array("jpg", "jpeg", "gif", "png");
$allowedTypes = array("image/gif", "image/jpeg", "image/jpg", "image/pjpeg","image/png");
$extension = end(explode(".", $_FILES["image"]["name"]));
$newfilename = time().".".$extension;
$filename = $_FILES["image"]["name"];
$filetmp = $_FILES["image"]["tmp_name"];
$filetype = $_FILES["image"]["type"];
$filesize = $_FILES["image"]["size"];
$filesize = number_format(( $filesize / 1024 ) / 1024 , 2);
if(!$_FILES["image"]["error"]){
if (in_array($filetype,$allowedTypes) && in_array($extension, $allowedExts))
{
if(($filesize < 2)) // check if file size less than 2 mb
move_uploaded_file($filetmp,"images/" . $newfilename);
else{
echo '<span class="bold">Image is too big</span>';
exit;
}
}else{
echo '<span class="bold">Invalid image, Supported formats jpeg, png, gif</span>';
exit;
}
}
$thumb = "thumb_".$newfilename;
imagecreatethumbnail($path.$newfilename,$path.$thumb,$imagesize /2 ,$imagesize /2);
//$thumb = thumbnail_box(imagecreatefromjpeg($path.$newfilename),$path.$thumb, 210, 150);
//imagedestroy($i);
if(!file_exists($path.$thumb)) {
echo "File not found";
exit;
}
$im = imagecreatefrompng($path.$thumb);
if(!$im) echo "Cant open image";
$w = imagesx($im);
$h = imagesy($im);
for( $i = 0; $i < $h; $i++ ) {
for( $j = 0; $j < $w; $j++ ) {
//if($j%2 == 0) continue;
$rgb = imagecolorat($im, $j, $i);
$a = ($rgb >> 24) & 0xFF;
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
$pixel = $characters[$index];
if($img_type == "gray"){
$gray = round(($r + $g + $b) / 3);
//if($gray > 0x7F) $gray = 0xFF;
//$gray = 0x00;
echo "<span style='color:rgb($gray,$gray,$gray);'>$pixel</span>";
}else{
echo "<span style='color:rgb($r,$g,$b);'>$pixel</span>";
}
//echo "<div style='background:rgb($r,$g,$b);float:left;width:1px; height:1px;'>@</div>";
$index++;
if($index >= count(str_split($characters)))
$index = 0;
}
echo "<br>";
}
unlink($path.$thumb);
unlink($path.$newfilename);
echo '</body></html>';
exit;
}
?>
<!DOCTYPE html>
<html lang="vi">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="content-type" content="text/html; UTF-8" />
<title>Chuyển Đổi Ảnh Sang Text</title>
</head>
<style>
.table td{
padding: 5px;
font-family: verdana;
font-size: 12px;
}
body h1{
font-family: verdana,arial,sans-serif;
text-shadow: 0px 2px 3px #666;
}
table.gridtable {
font-family: verdana,arial,sans-serif;
font-size:11px;
color:#333333;
border-width: 1px;
border-color: #BEBEBE;
border-collapse: collapse;
border-radius: 8px;
box-shadow: 0px 4px 6px #ADADAD;
}
table.gridtable th {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #BEBEBE;
background-color: #EBEBEB;
text-align: right;
}
table.gridtable td {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #BEBEBE;
background-color: #ffffff;
}
table.gridtable input[type="text"],select,input[type="file"]{
background: #F8F8F8;
padding: 3px;
border: 1px solid #C3C3C3;
border-radius: 3px;
width: 220px;
}
table.gridtable input[type="submit"]{
padding: 5px;
}
.tip{
color: #32688F;
margin-left: 10px;
}
</style>
<body>
<center>
<h1>Chuyển ảnh sang text</h1>
<form name="convert" method="POST" action="?" enctype="multipart/form-data">
<table width="60%" border="0" cellspacing="0" cellpadding="0" class="gridtable">
<tr>
<th width="20%"> Chọn ảnh : </th>
<td><input type="file" name="image"></td>
</tr>
<tr>
<th>Kí tự tạo chữ :</th>
<td><input type="text" name="characters" value="0"><span class="tip">(từ 0 -9)</span></td>
</tr>
<tr>
<th>Kích thước :</th>
<td>
<select name="fontsize" id="fontsize">
<option value="3">Siêu nhỏ</option>
<option value="5">Nhỏ</option>
<option selected="selected" value="8">Chuẩn</option>
<option value="10">Lớn</option>
<option value="12">Rất lớn</option>
</select><span class="tip">(càng nhỏ càng nhanh)</span>
</td>
</tr>
<tr>
<th>Kiểu ảnh</th>
<td>
<select name="img_type">
<option selected="selected" value="color">Chuẩn</option>
<option value="gray">Lệch</option>
</select><span class="tip">(Màu ảnh xuất ra)</span>
</td>
</tr>
<tr>
<th>Màu nền</th>
<td><input type="text" name="bgcolor" value="black"><span class="tip">(chuẩn nhất với màu đen)</span></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name ="ok" value="Chuyển Đổi"></td>
</tr>
</form>
</center>
</body>
</html>
Chụy Hiệp © 2016 | Đặt Quảng Cáo - Nội quy |