2 Steps to convert png into ico with phpthumb in php



Step 2: Use phpthumb to convert a png into ico

I have programmed a demo to show how to use phpthumb to convert a png into a ico file. Sample code below:


<?php
include "phpthumb.ico.php";
include "phpthumb.functions.php";

// step 1: get png image
$png_data=imagecreatefrompng ("stepor.png");

// step 2: convert png to ico
$gd_image_array = array($png_data);
$icon=new phpthumb_ico;
$ico_data = $icon->GD2ICOstring($gd_image_array);

// step 3: save ico image
$filename = "stepr.ico";
file_put_contents($filename,$ico_data);
?>

In this sample code, i convert a file called stepor.png into stepr.ico. and the result is below:

convert png to ico by php

Comparing stepor.png and ster.ico you can find, the quality and size of image are the same, the only difference of them is format, one is pnge and the other is ico.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>