Home > php教程 > PHP源码 > body text

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

PHP中文网
Release: 2016-05-23 08:39:26
Original
1428 people have browsed it

拿到一张图片,就是想把它大卸八块,一个像素一个像素给分离开,看看图片到底包含了哪些颜色值。这个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();
}
Copy after login

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();
}
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!