$h) { # # $adjusted_width = $w / $hm; # $half_width = $adjusted_width / 2; # $int_width = $half_width - $w_height; # # imagecopyresampled($dimg,$simg,-$int_width,0,0,0,$adjusted_width,$nh,$w,$h); # # } elseif(($w <$h) || ($w == $h)) { # # $adjusted_height = $h / $wm; # $half_height = $adjusted_height / 2; # $int_height = $half_height - $h_height; # # imagecopyresampled($dimg,$simg,0,-$int_height,0,0,$nw,$adjusted_height,$w,$h); # # } else { # imagecopyresampled($dimg,$simg,0,0,0,0,$nw,$nh,$w,$h); # } # # return $dimg; # } function rotate($image, $degrees, $qual = 0) { if(function_exists("imagerotate")) return imagerotate($image, $degrees, 0); else { function imagerotate($src_img, $angle) { $src_x = imagesx($src_img); $src_y = imagesy($src_img); if ($angle == 180) { $dest_x = $src_x; $dest_y = $src_y; } elseif ($src_x <= $src_y) { $dest_x = $src_y; $dest_y = $src_x; } elseif ($src_x >= $src_y) { $dest_x = $src_y; $dest_y = $src_x; } $rotate=imagecreatetruecolor($dest_x,$dest_y); imagealphablending($rotate, false); switch ($angle) { case 270: for ($y = 0; $y < ($src_y); $y++) { for ($x = 0; $x < ($src_x); $x++) { $color = imagecolorat($src_img, $x, $y); imagesetpixel($rotate, $dest_x - $y - 1, $x, $color); } } break; case 90: for ($y = 0; $y < ($src_y); $y++) { for ($x = 0; $x < ($src_x); $x++) { $color = imagecolorat($src_img, $x, $y); imagesetpixel($rotate, $y, $dest_y - $x - 1, $color); } } break; case 180: for ($y = 0; $y < ($src_y); $y++) { for ($x = 0; $x < ($src_x); $x++) { $color = imagecolorat($src_img, $x, $y); imagesetpixel($rotate, $dest_x - $x - 1, $dest_y - $y - 1, $color); } } break; default: $rotate = $src_img; }; return $rotate; } return imagerotate($image, $degrees); } } function cropTo4by3($image){ global $page; // Get dimensions of existing image $dimensions[0] = imagesx($image); $dimensions[1] = imagesy($image); $portrait = false; if($dimensions[0]<$dimensions[1]){ $portrait = true; $image = rotate($image, 90, 0); } //$canvas = cropImage($dimensions[0], (($dimensions[0]/4)*3), $image); $width = $dimensions[0]; $height = ($width/4)*3; // Prepare canvas $newheight = $height; $newwidth = $dimensions[0]; if($dimensions[1]<$height){ //$newheight = $dimensions[1]; //$width = $height; $newwidth = ($dimensions[1]/3)*4; $newheight = $dimensions[1]; } $canvas = imagecreatetruecolor($newwidth,$newheight); // Prepare image resizing and crop -- Center crop location // Generate the cropped image imagecopyresized($canvas, $image, 0, 0, 0, 0, $newwidth, $newheight, $width, $newheight); // Write image or fail imagedestroy($image); if($portrait) $canvas = rotate($canvas, 270, 0); return $canvas; } function rotateAndResizeImage($imageLocation, $degrees, $maxWidth=-1, $maxHeight=-1){ $image = imagecreatefromjpeg($imageLocation); $image = rotate($image, $degrees, 0); if($maxWidth>0&&$maxHeight>0) $image = image_resample($image, $maxWidth, $maxHeight, 1); imagejpeg($image,$imageLocation); } function rotateImage($imageLocation, $degrees){ $image = imagecreatefromjpeg($imageLocation); $image = rotate($image, $degrees, 0); imagejpeg($image,$imageLocation); } function image_overlap($background, $foreground, $corner=4,$padding=5, $overlapX=-1, $overlapY=-1, $transparancy=100){ $insertWidth = imagesx($foreground); $insertHeight = imagesy($foreground); $imageWidth = imagesx($background); $imageHeight = imagesy($background); if($overlapX==-1){ switch($corner){ case 1:{ $overlapX = $padding; $overlapY = $padding; break; } case 2:{ $overlapX = $imageWidth-$insertWidth-5; $overlapY = $padding; break; } case 3:{ $overlapX = $padding; $overlapY = $imageHeight-$insertHeight-5; break; } default:{ $overlapX = $imageWidth-$insertWidth-$padding; $overlapY = $imageHeight-$insertHeight-$padding; break; } } } imagecolortransparent($foreground,imagecolorat($foreground,0,0)); imagecopymerge($background,$foreground,$overlapX,$overlapY,0,0,$insertWidth,$insertHeight,$transparancy); return $background; } function image_overlap_text($background, $text, $transparancy=35){ $size = 30; $fontFile = "content/imageGallery/font.ttf"; $imageWidth = imagesx($background); $imageHeight = imagesy($background); $imageHyp = sqrt($imageWidth*$imageWidth+$imageHeight*$imageHeight); $textcolor = imagecolorallocate($background, 255, 255, 255); $angle = rad2deg(atan($imageHeight/$imageWidth)); $textImage = imagecreatetruecolor($imageWidth, $imageHeight); //21pixels $text_data = imagettfbbox ($size, 0, $fontFile, $text); $height = max($text_data[1], $text_data[3]) - min($text_data[5], $text_data[7]); $width = max($text_data[2], $text_data[4]) - min($text_data[0], $text_data[6]); $leftPush = ($imageHyp-$width)/2; $distFromBottom = abs((sin($angle)*$leftPush)-$height); $distFromLeft = abs(cos($angle)*$leftPush); imagefttext($textImage, $size, $angle, $distFromLeft, ($imageHeight-$distFromBottom), $textcolor, $fontFile, $text); $background = image_overlap($background, $textImage,1, 0, 0, 0, $transparancy); return $background; } function image_getProportionateHeight($origWidth, $origHeight, $newWidth){ return ($newWidth / $origWidth) * $origHeight; } function image_getProportionateHeight2($origWidth, $origHeight, $newWidth, $newHeight){ if(($origWidth >= $newWidth) || ($origHeight >= $newHeight)){ if ($newWidth && ($origWidth < $origHeight)) $newWidth = ($newHeight / $origHeight) * $origWidth; else $newHeight = ($newWidth / $origWidth) * $origHeight; } else{ $newWidth = $imageWidth; $newHeight = $imageHeight; } return $newHeight; } function isAnimatedGif($filename) { $filecontents=file_get_contents($filename); $str_loc=0; $count=0; while ($count < 2) # There is no point in continuing after we find a 2nd frame { $where1=strpos($filecontents,"\x00\x21\xF9\x04",$str_loc); if ($where1 === FALSE) { break; } else { $str_loc=$where1+1; $where2=strpos($filecontents,"\x00\x2C",$str_loc); if ($where2 === FALSE) { break; } else { if ($where1+8 == $where2) { $count++; } $str_loc=$where2+1; } } } if ($count > 1) { return(true); } else { return(false); } } function image_resample($image, $w, $h, $maintainAspectRatio){ $imageWidth = imagesx($image); $imageHeight = imagesy($image); if($maintainAspectRatio==1||$maintainAspectRatio==true){ if(($imageWidth >= $w) || ($imageHeight >= $h)){ if ($w && ($imageWidth < $imageHeight)) $w = ($h / $imageHeight) * $imageWidth; else $h = ($w / $imageWidth) * $imageHeight; } else{ $w = $imageWidth; $h = $imageHeight; } } $resampled = imagecreatetruecolor($w, $h); imagecopyresampled ($resampled, $image, 0, 0, 0, 0, $w, $h, $imageWidth, $imageHeight); return $resampled; } function image_resample_thumb($image, $w, $h, $maintainAspectRatio){ $imageWidth = imagesx($image); $imageHeight = imagesy($image); if((($imageWidth >= $w) || ($imageHeight >= $h))&&$imageWidth > $imageHeight){ $image = cropTo4by3($image); $imageWidth = imagesx($image); $imageHeight = imagesy($image); } $cropHeight = false; if($maintainAspectRatio==1||$maintainAspectRatio==true){ if(($imageWidth >= $w) || ($imageHeight >= $h)){ if ($w && ($imageWidth < $imageHeight)) $cropHeight = true; $h2 = ($w / $imageWidth) * $imageHeight; } else{ $w = $imageWidth; $h2 = $imageHeight; } } $resampled = imagecreatetruecolor($w, $h); if($cropHeight==true) imagecopyresampled ($resampled, $image, 0, 0, 0, 70, $w, $h2, $imageWidth, $imageHeight); else imagecopyresampled ($resampled, $image, 0, 0, 0, 0, $w, $h2, $imageWidth, $imageHeight); $resampled = cropTo4by3($resampled); return $resampled; } function image_createthumb($thumb,$image, $w,$h) { $ext = strtolower(strrev(substr(strrev($image), 0, strpos(strrev($image), ".")))); global $basedir; if(function_exists('gd_info')) { $serversupport = gd_info(); if(($ext == "jpg" && $serversupport["JPG Support"]) || ($ext == "gif" && $serversupport["GIF Read Support"] && $serversupport["GIF Create Support"]) || ($ext == "png" && $serversupport["PNG Support"])) { $imagedata = getimagesize($image); if(($imagedata[0] > $w) || ($imagedata[1] > $h)) { if ($w && ($imagedata[0] < $imagedata[1])) $w = ($h / $imagedata[1]) * $imagedata[0]; else $h = ($w / $imagedata[0]) * $imagedata[1]; } else { $w = $imagedata[0]; $h = $imagedata[1]; } switch($imagedata['mime']) { case "image/jpeg"; { $im2 = imagecreatetruecolor($w,$h); $image = imagecreatefromjpeg($image); imagecopyresampled ($im2, $image, 0, 0, 0, 0, $w, $h, $imagedata[0], $imagedata[1]); imagejpeg($im2, $thumb, 100); break; } case "image/gif"; { $im2 = imagecreatetruecolor($w,$h); $image = imagecreatefromgif($image); imagecopyresampled ($im2, $image, 0, 0, 0, 0, $w, $h, $imagedata[0], $imagedata[1]); imagegif($im2, $thumb, 100); break; } case "image/png"; { $im2 = imagecreatetruecolor($w,$h); $image = imagecreatefrompng($image); imagecopyresampled ($im2, $image, 0, 0, 0, 0, $w, $h, $imagedata[0], $imagedata[1]); imagepng($im2, $thumb, 100); break; } } return ""; } else return "No server support for $ext"; } else return "Server Does not support GD"; } ?>