Jump to content

PHP GD Alpha


konnwat

Recommended Posts

Im confused. I've got a 10 png images, with aplha, of the numbers 0-9 they all have the same hight but not the same width. I got a mysql database with a counter number and i made a counter works fine, but its not in aplha :s

 

heres my code...

<?php
//str_split
if(!function_exists('str_split')){
   function str_split($string,$split_length=1){
       $count = strlen($string); 
       if($split_length < 1){
           return false; 
       } elseif($split_length > $count){
           return array($string);
       } else {
           $num = (int)ceil($count/$split_length); 
           $ret = array(); 
           for($i=0;$i<$num;$i++){ 
               $ret[] = substr($string,$i*$split_length,$split_length); 
           } 
           return $ret;
       }     
   } 
}


//connect to mysql
$mysqlLink = mysql_connect(----------------);
mysql_select_db(--------------);


//get id
if(isset($_GET['id'])) {
$id = $_GET['id'];
} else {
$id = '1';
}


//get count number and +1
  $result = mysql_query("SELECT * FROM counters WHERE ID=".$id);
  $rows = mysql_fetch_array($result);
$count = $rows['Count'];
if ($_COOKIE[$id] != 'done') {
$count++;
mysql_query("UPDATE counters SET Count = '$count' WHERE ID=".$id);

//set cookie
setcookie($id, 'done', time()+60);
}


//split the count
$numbers = str_split($count);
$digits = count($numbers);

$nextwidth = 0;



//make image
header ("Content-type: image/png");
for($i=0; $i<$digits; $i++) {
list($width, $height, $type, $attr) = getimagesize("numbers/{$rows['Type']}/{$numbers[$i]}.png");
$nextwidth += $width;
}
$im = imagecreate($nextwidth, $height);
imagesavealpha($im, true);
$nextwidth = 0;

imagecolorallocate($im, 0, 0, 0);
for($i=0; $i<$digits; $i++) {
list($width, $height, $type, $attr) = getimagesize("numbers/{$rows['Type']}/{$numbers[$i]}.png");
$image[$i] = imagecreatefrompng("numbers/{$rows['Type']}/{$numbers[$i]}.png");
imagesavealpha($image[$i], true);
imagecopymerge($im,$image[$i], $nextwidth, 0, 0, 0, $width, $height, 100);
$nextwidth += $width;
}
imagesavealpha($im, true);
imagepng($im);
?>

 

i have imagesavealpha($im, true); in 3 times, i tried it everywhere :s

 

please help

thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.