index.php
Copy CodeThe code is as follows:
$output = "";
if (Isset ($_get[' action ')) &&$_get[' action '] = = ' make ') {
if (Isset ($_files[' upimage ' [' tmp_name ']) && $_files[' upimage ' [' tmp_name '] && is_uploaded_file ($_ files[' upimage ' [' tmp_name '])) {
if ($_files[' upimage ' [' type ']>210000) {
echo "The volume of your uploaded file exceeds the maximum limit of 200K";
Exit ();
}
$fileext = Array ("Image/pjpeg", "Image/gif", "image/x-png");
if (!in_array ($_files[' upimage ' [' type '], $fileext)) {
echo "The file you uploaded is not properly formatted to support jpg,gif,png only";
Exit ();
}
if ($im = @imagecreatefrompng ($_files[' upimage ' [' tmp_name ']) or $im = @imagecreatefromgif ($_files[' upimage '] [' Tmp_ Name ']) or $im = @imagecreatefromjpeg ($_files[' upimage ' [' tmp_name '])) {
$imginfo = @getimagesize ($_files[' upimage ' [' tmp_name ']);
if (!is_array ($imginfo)) {
echo "Graphic format Error! ";
}
Switch ($_post[' size ']) {
Case 1;
$resize _im = @imagecreatetruecolor (16,16);
$size = 16;
Break
Case 2;
$resize _im = @imagecreatetruecolor (32,32);
$size = 32;
Break
Case 3;
$resize _im = @imagecreatetruecolor (48,48);
$size = 48;
Break
Default
$resize _im = @imagecreatetruecolor (32,32);
$size = 32;
Break
}
Imagecopyresampled ($resize _im, $im, 0,0,0,0, $size, $size, $imginfo [0], $imginfo [1]);
Include "phpthumb.ico.php";
$icon = new Phpthumb_ico ();
$GD _image_array = Array ($resize _im);
$icon _data = $icon->gd2icostring ($gd _image_array);
$filename = "temp/". Date ("Ymdhis"). Rand (1,1000). ". ICO ";
if (File_put_contents ($filename, $icon _data)) {
$output = "Build succeeded! Click Save As saved to local
Click to download ";
}
}else{
echo "Build error Please try again!" ";
}
}
}
?>
<title>ico icon Online Conversion</title>
ico icon Online Conversion
phpthumb.ico.php
Copy CodeThe code is as follows:
//////////////////////////////////////////////////////////////
Phpthumb () by James Heinrich //
Available at http://phpthumb.sourceforge.net//
//////////////////////////////////////////////////////////////
/// //
Phpthumb.ico.php-. ICO output format Functions//
// ///
//////////////////////////////////////////////////////////////
Class Phpthumb_ico {
function Phpthumb_ico () {
return true;
}
Function gd2icostring (& $GD _image_array) {
foreach ($gd _image_array as $key = = $gd _image) {
$ImageWidths [$key] = Imagesx ($gd _image);
$ImageHeights [$key] = Imagesy ($gd _image);
$BPP [$key] = Imageistruecolor ($gd _image)? 32:24;
$totalcolors [$key] = Imagecolorstotal ($gd _image);
$icXOR [$key] = ';
for ($y = $ImageHeights [$key]-1; $y >= 0; $y-) {
for ($x = 0; $x < $ImageWidths [$key]; $x + +) {
$argb = $this->getpixelcolor ($gd _image, $x, $y);
$a = round (255 * (127-$argb [' alpha '])/127);
$r = $argb [' Red '];
$g = $argb [' green '];
$b = $argb [' Blue '];
if ($bpp [$key] = = 32) {
$icXOR [$key]. = Chr ($b). chr ($g). chr ($r). chr ($a);
} elseif ($bpp [$key] = = 24) {
$icXOR [$key]. = Chr ($b). chr ($g). chr ($R);
}
if ($a < 128) {
@ $icANDmask [$key] [$y]. = ' 1 ';
} else {
@ $icANDmask [$key] [$y]. = ' 0 ';
}
}
Mask bits is 32-bit aligned per scanline
while (strlen ($icANDmask [$key] [$y])% 32) {
$icANDmask [$key] [$y]. = ' 0 ';
}
}
$icAND [$key] = ';
foreach ($icANDmask [$key] as $y = = $scanlinemaskbits) {
for ($i = 0; $i < strlen ($scanlinemaskbits); $i + = 8) {
$icAND [$key]. = Chr (Bindec (Str_pad (substr ($scanlinemaskbits, $i, 8), 8, ' 0 ', str_pad_left)));
}
}
}
foreach ($gd _image_array as $key = = $gd _image) {
$biSizeImage = $ImageWidths [$key] * $ImageHeights [$key] * ($BPP [$key]/8);
BITMAPINFOHEADER-40 bytes
$BitmapInfoHeader [$key] = ';
$BitmapInfoHeader [$key]. = "\x28\x00\x00\x00"; DWORD bisize;
$BitmapInfoHeader [$key]. = $this->littleendian2string ($ImageWidths [$key], 4); LONG Biwidth;
The Biheight member specifies the combined
Height of the XOR and and masks.
$BitmapInfoHeader [$key]. = $this->littleendian2string ($ImageHeights [$key] * 2, 4); LONG Biheight;
$BitmapInfoHeader [$key]. = "\x01\x00"; WORD biplanes;
$BitmapInfoHeader [$key]. = Chr ($bpp [$key]). " \x00 "; Wbitcount;
$BitmapInfoHeader [$key]. = "\x00\x00\x00\x00"; DWORD bicompression;
$BitmapInfoHeader [$key]. = $this->littleendian2string ($biSizeImage, 4); DWORD biSizeImage;
$BitmapInfoHeader [$key]. = "\x00\x00\x00\x00"; LONG Bixpelspermeter;
$BitmapInfoHeader [$key]. = "\x00\x00\x00\x00"; LONG Biypelspermeter;
$BitmapInfoHeader [$key]. = "\x00\x00\x00\x00"; DWORD biclrused;
$BitmapInfoHeader [$key]. = "\x00\x00\x00\x00"; DWORD biclrimportant;
}
$icondata = "\x00\x00"; idreserved; Reserved (must be 0)
$icondata. = "\x01\x00"; Idtype; Resource Type (1 for icons)
$icondata. = $this->littleendian2string (count ($gd _image_array), 2); Idcount; How many images?
$dwImageOffset = 6 + (count ($gd _image_array) * 16);
foreach ($gd _image_array as $key = = $gd _image) {
Icondirentry Identries[1]; An entry for each image (Idcount of ' em)
$icondata. = Chr ($ImageWidths [$key]); Bwidth; Width, in pixels, of the image
$icondata. = Chr ($ImageHeights [$key]); Bheight; Height, in pixels, of the image
$icondata. = Chr ($totalcolors [$key]); Bcolorcount; Number of colors in image (0 if >=8bpp)
$icondata. = "\x00"; breserved; Reserved (must be 0)
$icondata. = "\x01\x00"; Wplanes; Color Planes
$icondata. = Chr ($bpp [$key]). " \x00 "; Wbitcount; Bits per pixel
$dwBytesInRes = + strlen ($icXOR [$key]) + strlen ($icAND [$key]);
$icondata. = $this->littleendian2string ($dwBytesInRes, 4); Dwbytesinres; How many bytes in this resource?
$icondata. = $this->littleendian2string ($dwImageOffset, 4); Dwimageoffset; Where in the file is this image?
$dwImageOffset + = strlen ($BitmapInfoHeader [$key]);
$dwImageOffset + = strlen ($icXOR [$key]);
$dwImageOffset + = strlen ($icAND [$key]);
}
foreach ($gd _image_array as $key = = $gd _image) {
$icondata. = $BitmapInfoHeader [$key];
$icondata. = $icXOR [$key];
$icondata. = $icAND [$key];
}
return $icondata;
}
function littleendian2string ($number, $minbytes =1) {
$intstring = ";
while ($number > 0) {
$intstring = $intstring. chr ($number & 255);
$number >>= 8;
}
Return Str_pad ($intstring, $minbytes, "\x00", str_pad_right);
}
Function Getpixelcolor (& $img, $x, $y) {
if (!is_resource ($img)) {
return false;
}
Return @ImageColorsForIndex ($img, @ImageColorAt ($img, $x, $y));
}
}
?>
http://www.bkjia.com/PHPjc/318401.html www.bkjia.com true http://www.bkjia.com/PHPjc/318401.html techarticle The index.php Copy code code is as follows:? PHP $output = ""; if (Isset ($_get[' action ')) $_get[' action ']== ' make ') {if (isset ' $_files[' [' upimage ']) tmp_name ' $_files[' [' Tmp_name ']IS_UPL ...