Skip to content

Instantly share code, notes, and snippets.

@dublado
Last active October 5, 2022 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dublado/1387044 to your computer and use it in GitHub Desktop.
Save dublado/1387044 to your computer and use it in GitHub Desktop.
resize png keeping transparency
<?php
function Resize($ImageFile,$OriginalFile)
{
$ext=basename($OriginalFile);
$ext=explode(".",$ext);
$ext=array_pop($ext);
$ext=strtolower($ext);
if ($ext=="jpg" or $ext=="jpeg" or $ext=="jpe")
$img=imagecreatefromjpeg($ImageFile);
elseif ($ext=="png")
$img=imagecreatefrompng($ImageFile);
elseif ($ext=="gif")
$img=imagecreatefromgif($ImageFile);
else
return false;
list($w,$h)=getimagesize($ImageFile);
$dstimg=imagecreatetruecolor(140,100);
imagealphablending($dstimg, false);
imagecopyresampled($dstimg,$img,0,0,0,0,140,100,$w,$h);
imagesavealpha($dstimg, true);
imagepng($dstimg,$ImageFile);
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment