Heim  >  Artikel  >  php教程  >  PHP像素拼图,牛哥是一枚自称设计师的程序员!

PHP像素拼图,牛哥是一枚自称设计师的程序员!

PHP中文网
PHP中文网Original
2016-05-23 08:39:261394Durchsuche

拿到一张图片,就是想把它大卸八块,一个像素一个像素给分离开,看看图片到底包含了哪些颜色值。这个php类从牛哥眼前飘过!

1.png

2.png

<?php
/**
 * 
 * 
 */
header("Content-type: text/html; charset=utf-8");       
include "pixpic.class.php";
$px = new Pixpic();
$img = "./niuge_weixi.png";
//你需要设置一个图片路径
$px->setImage($img);
//你需要初始化需要展示的像素大小
$pro = $px->getProperty();
if (!$px->error()) {
    $palete = $px->image2palete();
    echo "<p>Attributes Image:</p>";
    echo "<p>Width:" . $pro[0] . "</p>";
    echo "<p>Height:" . $pro[1] . "</p>";
    echo "<p>Bits:" . $pro["bits"] . "</p>";
    echo "<p>Type:" . $pro["mime"] . "</p>";
    echo "<h1>图片中包含的像素</h1>";
    foreach ($palete as $color)
        echo "<div style=&#39;background-color:#" . $color . ";width:20px;height:20px;float:left;margin-left:3px;margin-bottom:3px;border:1px solid&#39;></div>";
} else {
    echo $px->error();
}

3.png

<?php
/**
 * 
 * 
 */
include "pixpic.class.php";
$px=new Pixpic();
$img="./niuge_weixi.png";
//你需要设置一个图片路径
$px->setImage($img);
//你需要初始化需要展示的像素大小
$px->zoom=3;
$px->span=2;
if(!$px->error()){
    echo $px->image2div();
}else{
    echo $px->error();
}
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:简单计算方法Nächster Artikel:如何从php5升级到php7