Created
July 19, 2013 17:06
-
-
Save skvggor/6040752 to your computer and use it in GitHub Desktop.
Picturicon prototype
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Class Picturicon { | |
function addIcon($avatar, $icon, $saveAs) { | |
function x($image) { | |
$x = getimagesize($image); | |
return $x[0]; | |
} | |
function y($image) { | |
$y = getimagesize($image); | |
return $y[1]; | |
} | |
function createImage($image) { | |
if (exif_imagetype($image) == 1) { | |
$image = imagecreatefromgif($image); | |
} elseif (exif_imagetype($image) == 2) { | |
$image = imagecreatefromjpeg($image); | |
} elseif (exif_imagetype($image) == 3) { | |
$image = imagecreatefrompng($image); | |
} | |
return $image; | |
} | |
if ($avatar && $icon) { | |
$resAvatar = x($avatar) * y($avatar); | |
$resIcon = x($icon) * y($icon); | |
if ($resAvatar >= $resIcon) { | |
$canvas = createImage($avatar); | |
$layer1 = createImage($avatar); | |
$layer2 = createImage($icon); | |
$iconX = x($avatar) - x($icon); | |
$iconY = y($avatar) - y($icon); | |
imagecopy( | |
$canvas, | |
$layer2, | |
$iconX, $iconY, | |
0, 0, | |
x($icon), y($icon) | |
); | |
imagecopymerge( | |
$layer1, | |
$canvas, | |
$iconX, $iconY, | |
0, 0, | |
x($icon), y($icon), | |
100 | |
); | |
imagepng($canvas, $saveAs); | |
imagedestroy($layer2); | |
imagedestroy($canvas); | |
} else { | |
echo "Picturicon: The avatar is smaller than the icon! Restart processing."; | |
} | |
} else { | |
echo "Picturicon: Missing file (s) to process. Restart processing."; | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment