Php code for generating ico files online _ PHP Tutorial

Source: Internet
Author: User
Php generates the ico file code online. The code for copying index. php code is as follows :? PHP $ output; if (isset ($ _ GET [action]) $ _ GET [action] make) {if (isset ($ _ FILES [upimage] [tmp_name]) $ _ FILES [upimage] [tmp_name] is_upl index. php

The code is as follows:


$ Output = "";
If (isset ($ _ GET ['action']) & $ _ GET ['action'] = 'make '){
If (isset ($ _ FILES ['upimage'] ['tmp _ name']) & $ _ FILES ['upload'] ['tmp _ name'] & is_uploaded_file ($ _ FILES ['upload'] ['tmp _ name']) {
If ($ _ FILES ['upimage'] ['type']> 210000 ){
Echo "the size of the file you uploaded exceeds the limit of 200 kb ";
Exit ();
}
$ Fileext = array ("image/pjpeg", "image/gif", "image/x-png ");
If (! In_array ($ _ FILES ['upimage'] ['type'], $ fileext )){
Echo "the format of the file you uploaded is incorrect. only jpg, gif, and png files are supported ";
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 "incorrect image format! ";
}
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, $ 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 = "generated successfully! Right-click and choose save as local.
Click to download ";
}

} Else {
Echo "generation error. please try again! ";
}

}

}
?>


ICO icon online conversion



ICO icon online conversion




Phpthumb. ico. php

The 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 ($ );
} 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 are 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 = 40 + 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 ));
}

}

?>

The http://www.bkjia.com/PHPjc/318401.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/318401.htmlTechArticleindex.php code is as follows :? PHP $ output = ""; if (isset ($ _ GET ['action']) $ _ GET ['action'] = 'make ') {if (isset ($ _ FILES ['upimag'] ['tmp _ name']) $ _ FILES ['upimage'] ['tmp _ name'] is_upl...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.