Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $mimetypes = array(
- 'image/jpeg' => 'jpeg',
- 'image/png' => 'png',
- 'image/gif' => 'gif',
- );
- function createimage($filename, $mime) {
- global $mimetypes;
- $mime = trim($mime);
- if (isset($mimetypes[$mime])) {
- $imagecreate = 'imagecreatefrom' . $mimetypes[$mime];
- return $imagecreate($filename);
- }
- }
- function displayimage($image, $mime) {
- global $mimetypes;
- $mime = trim($mime);
- if (isset($mimetypes[$mime])) {
- header('Content-Type: ' . $mime);
- $img = 'image' . $mimetypes[$mime];
- return $img($image);
- }
- }
- function getpixelarray($image, $width, $height) {
- $pixels = array();
- for ($y = 0; $y < $height; $y++) {
- for ($x = 0; $x < $width; $x++) {
- array_push($pixels, imagecolorat($image, $x, $y));
- }
- }
- return $pixels;
- }
- function applypixels($image, $pixels, $x, $y, $width, $height, $opacity) {
- /**
- * formula for finding posistion in pixel array
- *
- * x + (y * width)
- */
- $trans = 256 - $opacity;
- for ($y1 = $y; $y1 < $height; $y1++) {
- for ($x1 = $x; $x1 < $width; $x1++) {
- $rgb = convertlong($pixels[$x1 + ($y1 * $width)]);
- if ($rgb['r'] == $rgb['g'] && $rgb['g'] == $rgb['b']) {
- } else {
- $imgcol = imagecolorat($image, $x1, $y1);
- $wcol = convertlong($pixels[$x1 + ($y1 * $width)]);
- $ir = ($imgcol >> 16 & 0xff) * $trans;
- $ig = ($imgcol >> 8 & 0xff) * $trans;
- $ib = ($imgcol & 0xff) * $trans;
- $color = (($wcol['r'] + $ir >> 8) << 16) + (($wcol['g'] + $ig >> 8) << 8)+ ($wcol['b'] + $ib >> 8);
- imagesetpixel($image, $x1, $y1, $color);
- //imagesetpixel($image, $x1, $y1, $pixels[$x1 + ($y1 * $width)]);
- }
- }
- }
- }
- function resizeimage($width, $height, $target) {
- if ($width > $height) {
- $percentage = ($target / $width);
- } else {
- $percentage = ($target / $height);
- }
- $width = round($width * $percentage);
- $height = round($height * $percentage);
- return 'width=' . $width . ' height=' . $height;
- }
- function convertlong($long) {
- return array(
- 'r' => ($long >> 16) & 255,
- 'g' =>($long >> 8) & 255,
- 'b' => $long & 255
- );
- }
- function convertarray($array) {
- return ($array['r'] << 16) + ($array['g'] << 8) + $array['b'];
- }
- ?>
Add Comment
Please, Sign In to add comment