reset and begin
Showing posts with label php. Show all posts

10/08/2010

Vẽ Biểu đồ dạng cột php

<?php
header("Content-type: image/gif");
$cells = array ("A"=>1275,"B"=>1312,"C"=>17 ,"D"=>200);
$max = max( $cells );
$total = count ( $cells );
$totalwidth = 556;
$totalheight = 120;
$xgutter = 100; // left/right margin
$ygutter = 20; // top/bottom margin
$internalgap = 10; // space between cells
$bottomspace = 30; // gap at the bottom (in addition to margin)
if(!isset($font))
$font = "C:\Windows\Fonts\arial.ttf";

$graphCanX = ( $totalwidth - $xgutter*2 );
$graphCanY = ( $totalheight - $ygutter*2 - $bottomspace );// starting draw position x - axis
$posX = $xgutter; // starting draw pos - y -  axis
$posY = $totalheight - $ygutter - $bottomspace;
$cellwidth = (int) (( $graphCanX - ( $internalgap * ( $total-1 ) )) / $total) ;
$textsize = (int)($bottomspace);
// adjust font size
while ( list( $key, $val ) = each ( $cells ) )
{
while ( 1 )
{
$box = imagettfbbox($textsize,0,$font,$key );
$textWidth = abs( $box[2] );
if ( $textWidth < $cellwidth )
break;
$textsize--;
}
}
$image = imagecreate( $totalwidth, $totalheight );
$red = imagecolorallocate($image, 224, 224, 224);
$blue = imagecolorallocate($image, 0, 0, 255 );
$black = imagecolorallocate($image, 0, 0, 0 );
$grey = imagecolorallocate($image, 100, 100, 100 );
reset ($cells);
while ( list( $key, $val ) = each ( $cells ) )
{
$cellheight = (int) (($val/$max) * $graphCanY);
$center = (int)($posX+($cellwidth/2));
imagefilledrectangle( $image, $posX, ($posY-$cellheight), ($posX+$cellwidth), $posY, $blue );
$box = imagettfbbox( $textsize, 0, $font, $key );
$tw = $box[2];
imagettftext(    $image, $textsize, 0, ($center-($tw/2)),
($totalheight-$ygutter), $black, $font, $key );
$posX += ( $cellwidth + $internalgap);
}
imagegif($image);
?>

function.imagettfbbox]: Invalid font filename in do đường dẫn đến file .ttf sai

vẽ biểu đồ dạng tròn php

<?php
$myImage = ImageCreate(300,300);

$white = ImageColorAllocate ($myImage, 255, 255, 255);
$red = ImageColorAllocate ($myImage, 255, 0, 0);
$green = ImageColorAllocate ($myImage, 0, 255, 0);
$blue = ImageColorAllocate ($myImage, 0, 0, 255);
$lt_red = ImageColorAllocate($myImage, 255, 150, 150);
$lt_green = ImageColorAllocate($myImage, 150, 255, 150);
$lt_blue = ImageColorAllocate($myImage, 150, 150, 255);

for ($i = 120;$i > 100;$i--) {
ImageFilledArc ($myImage, 100, $i, 200, 150, 0, 90, $lt_red, IMG_ARC_PIE);
ImageFilledArc ($myImage, 100, $i, 200, 150, 90, 180, $lt_green, IMG_ARC_PIE);
ImageFilledArc ($myImage, 100, $i, 200, 150, 180, 360, $lt_blue, IMG_ARC_PIE);
}

ImageFilledArc($myImage, 100, 100, 200, 150, 0, 90, $red, IMG_ARC_PIE);
ImageFilledArc($myImage, 100, 100, 200, 150, 90, 180 , $green, IMG_ARC_PIE);
ImageFilledArc($myImage, 100, 100, 200, 150, 180, 360 , $blue, IMG_ARC_PIE);

header ("Content-type: image/png");
ImagePNG($myImage);

ImageDestroy($myImage);
?>

8/17/2010

chụp ảnh màn hình với php

TH 1- chụp toàn bộ ie

<?php
$browser = new COM("InternetExplorer.Application");
$handle = $browser->HWND;
$browser->Visible = true;
$im = imagegrabwindow($handle);
$browser->Quit();
imagepng($im, "iesnap.png");
imagedestroy($im);
?>

TH 2

$browser = new COM("InternetExplorer.Application");
$handle = $browser->HWND;
$browser->Visible = true;
$browser->Navigate("http://www.gigame.tk");

/* Still working? */
while ($browser->Busy) {
com_message_pump(4000);
}
$im = imagegrabwindow($handle, 0);
$browser->Quit();
imagepng($im, "iesnap.png");
imagedestroy($im);


TH3- chụp cả màn hình



<?php
$im = imagegrabscreen();
imagepng($im, "myscreenshot.png");
imagedestroy($im);
?>

khi truy ảnh , ảnh trả lại màu đen bạn cần config server

Start menu > Control Panel > Administrative Tools > Services > Right-click  Wampapache and select Properties ->log on

the Log On tab, check "Allow service to interact with desktop" checkbox.




7/21/2010

tạo chữ trên ảnh với php text over(on) image in php

<?php

//PHP's GD class functions can create a variety of output image
//types, this example creates a jpeg
header("Content-Type: image/jpeg");

//open up the image you want to put text over
$im = imagecreatefromgif("a.gif");

//The numbers are the RGB values of the color you want to use
$black = imagecolorallocate($im, 24, 55, 55);
$x = imagesx($im);
$y = imagesy($im);
//The canvas's (0,0) position is the upper left corner
//So this is how far down and to the right the text should start
$start_x = 0;
$start_y = $y-16;

//This writes your text on the image in 12 point using verdana.ttf
//For the type of effects you quoted, you'll want to use a truetype font
//And not one of GD's built in fonts. Just upload the ttf file from your
//c: windows fonts directory to your web server to use it.
imagettftext($im, 16, 0, $start_x, $start_y, $black, 'f.ttf', "HTTP://DOCNHAT.TK  ");

//Creates the jpeg image and sends it to the browser
//100 is the jpeg quality percentage
imagejpeg($im,'', 100);

imagedestroy($im);

?>

7/20/2010

ghi dữ liệu với xml

list.xml

<?xml version="1.0" encoding="utf-8"?>
<playlist xmlns="http://xspf.org/ns/0/" version="1">
<trackList>
<track>
<title>Thụy Anh</title>
<creator>Một Phút Yêu (Demo)</creator>
<location>http://musicbox.vn/khonhac/1phutyeu(demo).mp3</location>
<image>mp3/kz.gif</image>
<info>http://Docnhat.tk</info>

</track>

<track><title>day la title</title></track>
<track><title>day la title</title></track>
</trackList>
</playlist>
index.php

$dom = new DOMDocument();
$dom->load('list.xml');

$tracklist=$dom->getElementsByTagName('trackList')->item(0);
$track=$dom->createElement('track');

$title=$dom->createElement('title','day la title');
$track->appendChild($title);

$tracklist->appendChild($track);
$dom->save("list.xml");

7/09/2010

tìm ước chung lớn nhất

function ucln($a,$b)
{      $a=abs($a);
$b=abs($b);
if ($a==0 ||$b==0)
return $a+$b;
while ($a !=$b)
{
if($a>$b)
$a=$a-$b;
else
$b=$b-$a;
}
return $a;
}

echo ucln(42,56);

trong C#

static int USCLN(int a, int b)
       {
a=Math.Abs(a);
b=Math.Abs(b);
if (a==0 ||b==0)
return a+b;
while (a !=b)
{
if(a>b)
a=a-b;
else
b=b-a;
}
return a;
}



[caption id="" align="alignnone" width="241" caption="ucnn"]ucnn[/caption]

chuyển đổi hệ thập phân sang -> nhị phân hay các hệ khác

function chuyen($sc,$h){
if($sc>=$h) {chuyen($sc/$h,$h);}
echo $sc%$h;
}
chuyen(60,2);

Ví dụ như ta đổi số n trong Dec sang cơ số a thì sẽ là :
+ Lấy n chia cho a được thương q1 dư r1
+ Lấy q1 chia cho a được thương q2 dư r2
cứ vậy tiếp tục cho đến khi ta được thương qn < a thì dừng lại
khi đó dãy qn r(n-1) r(n-2) ... r1 là số n trong cơ số a.
Đối với các cơ số > 10 thì ta phải thêm các chữ cái vào để đủ bộ "chữ số"

List

Profiles Information


About me : Nothing is 1 vài thứ - 1985

Places I've Lived : I Hà Nội

Home Page : http://www.shimivn.blogspot.com/

Think : 1:1000000000

Languages spoken : Vietnamese,English.

Mobile : sony C2305

dell : i3-Ram 3GB- HDD 250GB .