sammensæt php
Jeg har to script som jeg gerne vil have kombineretFølgendene script udhenter filer fra mappe og mysql
jeg vil gerne have an analyse af alle de billeder der bliver udhentet:
<?
include('admin/config.php');
//A connection to MySQL is created
mysql_connect($mysql['host'],$mysql['user'],$mysql['password']) or die (mysql_error());
mysql_select_db($mysql['db']) or die (mysql_error());
$result = mysql_query("SELECT * FROM `site_module` ORDER BY `time` DESC");
function removeThumbDB($imgs){
$i = 0;
foreach($imgs AS $img){
if(strtolower(basename($img))=="thumbs.db"){
unset($imgs[$i]);
} else if(substr($img, -6) != "-b.jpg") {
unset($imgs[$i]);
}
$i++;
}
natsort($imgs);
return $imgs;
}
function rgb2hex($rgb){
$cols = array_slice($rgb,0,3);
$out = '#';
foreach($cols AS $col){
$out .= strtoupper(str_pad(dechex($col), 2, 0, STR_PAD_LEFT));
}
return $out;
}
function debug($input){
echo '<pre>'.print_r($input,true).'</pre>';
}
if(isset($_REQUEST['type'])) {
$type_url = $_REQUEST['type'];
$type_url_link = '_'.$_REQUEST['type'];
} else {
$type_url = 'flash';
$type_url_link = '_flash';
}
$folders = glob($type_url.'/*');
$cols = 6;
$i = 0;
$count = 0;
echo "<table><tr>";
foreach($folders AS $folder){
if(is_dir($folder)){
if($cols==$i){
echo "</tr><tr>";
$i=0;
}
$dir = $folder.'/site_flash/';
$imgs = removeThumbDB(glob($folder.'/screenshots/*'));
$img = $imgs[array_rand($imgs, 1)];
echo "<td><center><a href='".$img."' rel='lightbox[roadtrip]' title='<a href="".$folder."/site".$type_url_link."/".basename($folder).".html"><img src="images/eye.png" width="22" /> Se siden ".basename($folder)." her</a>'><img src='".$img."' alt='".basename($img)."' height='100' alt='".basename($folder)."' border='0' /><br>";
$files2 = scandir($dir, 1);
$xml_i=0;
foreach($files2 AS $go){
$ext = strtolower(substr($go, strrpos($go, '.')+1));
if ($ext == 'xml') {
if(!$xml_i >= 1){
echo "V";
echo "<br />";
//For at smide alle xml'er i databasen flern // og gå til siden husk at sæt dem igen efter
//mysql_query("INSERT INTO `site_module` SET `nr`='" . basename($folder) . "', `type`='flash', `title`='" . basename($folder) . "', `xml`='1', `url`='" . $type_url_link . "', `time`='" . time() . "'") or die (mysql_error());
}
$xml_i++;
}
}
mysql_data_seek($result, 0);
while($row = mysql_fetch_array($result)) {
if($row['nr']==basename($folder)) {
echo $row['title']."<b>";
}
}
echo "</b></a><br>";
if ($_GET["colour_num"]) {
$image = imagecreatefromjpeg($img);
$colors = array();
if($image){
$width = imagesx($image);
$height = imagesy($image);
for($y = 0; $y < $height; ++$y){
for($x = 0; $x < $width; ++$x){
$thiscol = imagecolorat($image, $x, $y);
$rgb = imagecolorsforindex($image, $thiscol);
$colors[] = rgb2hex($rgb);
}
}
}
$counts = array_count_values($colors);
arsort($counts);
$top5 = array_slice($counts,0,$_GET["colour_num"]);
/*debug($top5);*/
foreach ($top5 as $top5_key => $top5_value) {
echo '<span style="border:1px solid; background:' . $top5_key . '" alt="' . $top5_value . '" title="' . $top5_value . '"> </span>';
}
}
echo "</center></td>\n";
$i++;
$count++;
}
}
echo "</tr></table>";
echo "Der er vist \"" . $count . "\"Sider";
?>
Og dette er det farve analyse script jeg har fundet:
<?php
date_default_timezone_set("europe/copenhagen");
require_once("ColorCompare.php");
// files to be tested
$filenames = array(
"timthumb.png",
"test1.png"
);
// max colors
$max_colors = 8;
// loop through each test pattern
for ($i = 0; $i < count($filenames); $i++)
{
print "<table><tr><td><img src='{$filenames[$i]}'></td>\n";
$result = ColorCompare::compare($max_colors, $filenames[$i]);
print "<td><table width='200' border='1'>";
if ($result == false)
print "<tr><td>[failed]</td></tr>\n";
else
{
print "<tr><td><b>Color</b></td><td><b>Pixel Count</b></td></tr>";
foreach ($result as $color => $count)
{
print "<tr><td width='50' bgcolor='#".ColorCompare::$swatches[$color]
."'>#".ColorCompare::$swatches[$color]
."</td><td>".$count."</td></tr>\n";
}
}
print "</table></td></tr></table><br><hr><br>\n";
}
?>