How can I draw a sketch (line diagram) in php ?

Dear Friends,
I am a structural engineer. I am using php for developing a program for civil engineers.
I just want to know how can I draw a sketch or line diagram in php ?

Thanks in advance

I use this code and it works. but it needs gw libraries:

<?

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

$imgWidth=300;

$imgHeight=300;

// Create image and define colors

$image=imagecreate($imgWidth, $imgHeight);

$colorWhite=imagecolorallocate($image, 255, 255, 255);
$colorBlack=imagecolorallocate($image, 0, 0, 0);

$colorGrey=imagecolorallocate($image, 192, 192, 192);

$colorBlue=imagecolorallocate($image, 0, 0, 255);
$colorDarkBlue=imagecolorallocate($image, 51, 51, 204);
$colorLightBlue=imagecolorallocate($image, 0, 187, 255);

// Create border around image

imageline($image, 0, 0, 0, 249, $colorGrey);

imageline($image, 0, 0, 299, 0, $colorGrey);

imageline($image, 299, 0, 299, 249, $colorGrey);

imageline($image, 0, 249, 299, 249, $colorGrey);

// Create grid
/*

for ($i=1; $i<3; $i++){

imageline($image, $i*25, 0, $i*25, 250, $colorGrey);

imageline($image, 0, $i*25, 250, $i*25, $colorGrey);

}
*/
// Create line graph

for ($i=1; $i<=3; $i++){

imagefilledrectangle($image, $i*75, 100, $i*75+25, 250, $colorDarkBlue);

imagefilledrectangle($image, ($i*75)+1, 100, ($i*75+25)-5, 248, $colorLightBlue);

if($i == 1)
imagestring($image, 12, $i*75-2, 275, "good", $colorBlack);
if($i == 2)
imagestring($image, 12, $i*75-3, 275, "middle", $colorBlack);
if($i == 3)
imagestring($image, 12, $i*75-2, 275, "bad", $colorBlack);

}

// Output graph and clear image from memory

imagepng($image);

imagedestroy($image);

?>

4 Responses to “How can I draw a sketch (line diagram) in php ?”

  • Kasey C says:

    You don’t. There are no "drawing" commands in PHP.

    You’ll need to generate the picture / diagram some other way.
    References :

  • Kyle says:

    you would have to have a program designed to draw or whatever that supports php, you can’t just draw straight from any language.
    References :

  • Anton says:

    You can generate a picture file with php.
    Take a look at imagecreate and imageline functions.
    If you want to draw diagrams you can try jpgraph library (http://www.aditus.nu/jpgraph/)
    Also it is possible to call external programs from php that can generate such sketches or diagrams.
    References :
    http://ru.php.net/manual/en/function.imagecreate.php
    http://ru.php.net/manual/en/function.imageline.php

  • mahdi says:

    I use this code and it works. but it needs gw libraries:

    <?

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

    $imgWidth=300;

    $imgHeight=300;

    // Create image and define colors

    $image=imagecreate($imgWidth, $imgHeight);

    $colorWhite=imagecolorallocate($image, 255, 255, 255);
    $colorBlack=imagecolorallocate($image, 0, 0, 0);

    $colorGrey=imagecolorallocate($image, 192, 192, 192);

    $colorBlue=imagecolorallocate($image, 0, 0, 255);
    $colorDarkBlue=imagecolorallocate($image, 51, 51, 204);
    $colorLightBlue=imagecolorallocate($image, 0, 187, 255);

    // Create border around image

    imageline($image, 0, 0, 0, 249, $colorGrey);

    imageline($image, 0, 0, 299, 0, $colorGrey);

    imageline($image, 299, 0, 299, 249, $colorGrey);

    imageline($image, 0, 249, 299, 249, $colorGrey);

    // Create grid
    /*

    for ($i=1; $i<3; $i++){

    imageline($image, $i*25, 0, $i*25, 250, $colorGrey);

    imageline($image, 0, $i*25, 250, $i*25, $colorGrey);

    }
    */
    // Create line graph

    for ($i=1; $i<=3; $i++){

    imagefilledrectangle($image, $i*75, 100, $i*75+25, 250, $colorDarkBlue);

    imagefilledrectangle($image, ($i*75)+1, 100, ($i*75+25)-5, 248, $colorLightBlue);

    if($i == 1)
    imagestring($image, 12, $i*75-2, 275, "good", $colorBlack);
    if($i == 2)
    imagestring($image, 12, $i*75-3, 275, "middle", $colorBlack);
    if($i == 3)
    imagestring($image, 12, $i*75-2, 275, "bad", $colorBlack);

    }

    // Output graph and clear image from memory

    imagepng($image);

    imagedestroy($image);

    ?>
    References :
    m_kiani.allamehelli.ir/showidea.php

Leave a Reply