Preserve GIF transparency after imagecopyresampled

January 4th, 2008

Ok, seriously give Martin Schmidt some serious accolades on this because this solution is a very rare find and even tougher to figure out on your own. Thanks Martin!

  1.  
  2. //Begin Transparent Color Resize Correction for Gif and 8bit Png, by Martin Schmidt
  3. $destImg = imagecreatetruecolor( $picx, $picy );
  4. $colorcount = imagecolorstotal($logoImg);
  5. imagetruecolortopalette($destImg,true,$colorcount);
  6. imagepalettecopy($destImg,$logoImg);
  7. $transparentcolor = imagecolortransparent($logoImg);
  8. imagefill($destImg,0,0,$transparentcolor);
  9. imagecolortransparent($destImg,$transparentcolor);
  10. //End Transparent Color Resize Correction

Leading zeros - the easy way

September 20th, 2007

Most web developers will say you have to do all these IF statements and what-not just to get a zero in front of a number. Example, I want an 8 digit date (mmddyyyy). ASP will only generate a single digit “1″ for January and a single digit “1″ for the first. This means I end up with 112007. Not good. Here’s a sample to solve this problem :

<%
str= “1″
str=right(”00″ & str, 2) // returns “01″

%>

Perfect! What this is doing is adding 00 to str, so it then becomes “001″, then it takes the two right-most characters. Returning “01″. This is good because if you have a two digit day or month, then the two right-most characters are the two digits of that day or month. Bam! Easy huh?

Reset a result source in PHP with mysql_data_seek

August 28th, 2007
  1.  
  2. mysql_connect("host","user","pass");
  3. $result = mysql_query("SELECT names FROM table;");
  4. $result2 = mysql_query("SELECT names FROM table2;");          
  5.  
  6. while($row=mysql_fetch_array($result,MYSQL_ASSOC)) {
  7.         mysql_data_seek($result,0);
  8. while($row2=mysql_fetch_array($result2,MYSQL_ASSOC)) {
  9.                 if($row[‘name’]==$row2[‘name’])
  10.                         print "Match!";
  11.         }          
  12.  
  13. }