function compatible($Media) { $types = imageTypes(); if ($types & IMG_GIF) { $this->require['mimeTypes'][] = 'image/gif'; } if ($types & IMG_JPG) { $this->require['mimeTypes'][] = 'image/jpeg'; } if ($types & IMG_PNG) { $this->require['mimeTypes'][] = 'image/png'; } if ($types & IMG_WBMP) { $this->require['mimeTypes'][] = 'image/wbmp'; } if ($types & IMG_XPM) { $this->require['mimeTypes'][] = 'image/xpm'; } return parent::compatible($Media); }
/** * Generate images of alternate sizes. */ function resizeImage($cnvrt_arry) { global $platform, $imgs, $cnvrt_path, $reqd_image, $convert_writable, $convert_magick, $convert_GD, $convert_cmd, $cnvrt_alt, $cnvrt_mesgs, $compat_quote; if (empty($imgs) || $convert_writable == FALSE) { return; } if ($convert_GD == TRUE && !($gd_version = gdVersion())) { return; } if ($cnvrt_alt['no_prof'] == TRUE) { $strip_prof = ' +profile "*"'; } else { $strip_prof = ''; } if ($cnvrt_alt['mesg_on'] == TRUE) { $str = ''; } foreach ($imgs as $img_file) { if ($cnvrt_alt['indiv'] == TRUE && $img_file != $reqd_image['file']) { continue; } $orig_img = $reqd_image['pwd'] . '/' . $img_file; $cnvrtd_img = $cnvrt_path . '/' . $cnvrt_arry['prefix'] . $img_file; if (!is_file($cnvrtd_img)) { $img_size = GetImageSize($orig_img); $height = $img_size[1]; $width = $img_size[0]; $area = $height * $width; $maxarea = $cnvrt_arry['maxwid'] * $cnvrt_arry['maxwid'] * 0.9; $maxheight = $cnvrt_arry['maxwid'] * 0.75 + 1; if ($area > $maxarea || $width > $cnvrt_arry['maxwid'] || $height > $maxheight) { if ($width / $cnvrt_arry['maxwid'] >= $height / $maxheight) { $dim = 'W'; } if ($height / $maxheight >= $width / $cnvrt_arry['maxwid']) { $dim = 'H'; } if ($dim == 'W') { $cnvt_percent = round(0.9375 * $cnvrt_arry['maxwid'] / $width * 100, 2); } if ($dim == 'H') { $cnvt_percent = round(0.75 * $cnvrt_arry['maxwid'] / $height * 100, 2); } // convert it if ($convert_magick == TRUE) { // Image Magick image conversion if ($platform == 'Win32' && $compat_quote == TRUE) { $winquote = '"'; } else { $winquote = ''; } exec($winquote . $convert_cmd . ' -geometry ' . $cnvt_percent . '%' . ' -quality ' . $cnvrt_arry['qual'] . ' -sharpen ' . $cnvrt_arry['sharpen'] . $strip_prof . ' "' . $orig_img . '"' . ' "' . $cnvrtd_img . '"' . $winquote); $using = $cnvrt_mesgs['using IM']; } elseif ($convert_GD == TRUE) { // GD image conversion if (eregi('\\.jpg$|\\.jpeg$', $img_file) == TRUE && (imageTypes() & IMG_JPG) == TRUE) { $src_img = imageCreateFromJpeg($orig_img); } elseif (eregi('\\.gif$', $img_file) == TRUE && (imageTypes() & IMG_PNG) == TRUE) { $src_img = imageCreateFromPng($orig_img); } elseif (eregi('\\.gif$', $img_file) == TRUE && (imageTypes() & IMG_GIF) == TRUE) { $src_img = imageCreateFromGif($orig_img); } else { continue; } $src_width = imageSx($src_img); $src_height = imageSy($src_img); $dest_width = $src_width * ($cnvt_percent / 100); $dest_height = $src_height * ($cnvt_percent / 100); if ($gd_version >= 2) { $dst_img = imageCreateTruecolor($dest_width, $dest_height); imageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $src_width, $src_height); } else { $dst_img = imageCreate($dest_width, $dest_height); imageCopyResized($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $src_width, $src_height); } imageDestroy($src_img); if (eregi('\\.jpg$|\\.jpeg$/i', $img_file) == TRUE && (imageTypes() & IMG_JPG) == TRUE) { imageJpeg($dst_img, $cnvrtd_img, $cnvrt_arry['qual']); } elseif (eregi('\\.gif$', $img_file) == TRUE && (imageTypes() & IMG_PNG) == TRUE) { imagePng($dst_img, $cnvrtd_img); } elseif (eregi('\\.gif$/i', $img_file) == TRUE && (imageTypes() & IMG_GIF) == TRUE) { imageGif($dst_img, $cnvrtd_img); } imageDestroy($dst_img); $using = $cnvrt_mesgs['using GD'] . $gd_version; } if ($cnvrt_alt['mesg_on'] == TRUE && is_file($cnvrtd_img)) { $str .= " <small>\n" . ' ' . $cnvrt_mesgs['generated'] . $cnvrt_arry['txt'] . $cnvrt_mesgs['converted'] . $cnvrt_mesgs['image_for'] . $img_file . $using . ".\n" . " </small>\n <br />\n"; } } } } if (isset($str)) { return $str; } }
private function outputImage() { if (imageTypes() & IMG_GIF) { header("Content-type:image/gif"); imagegif($this->image); } elseif (imageTypes() & IMG_JPG) { header("Content-type:image/jpeg"); imagejpeg($this->image); } elseif (imageTypes() & IMG_PNG) { header("Content-type:image/png"); imagepng($this->image); } elseif (imageTypes() & IMG_WBMP) { header("Content-type:image/vnd.wap.wbmp"); imagewbmp($this->image); } else { die("the GD is closed"); } }
function getGdLibraryInfo() { if (!extension_loaded('gd')) { return ''; } /* Get GD version from phpinfo or gd_info */ if (function_exists('gd_info')) { $gdInfo = gd_info(); $matchString = $gdInfo['GD Version']; $matcherVersion = '/([\\d\\.]+)(\\s+or\\s+higher)?/i'; $matcherBundled = '/bundled/i'; } else { ob_start(); phpinfo(8); $matchString = ob_get_contents(); $matcherVersion = '/\\bgd\\s+version\\b[^\\d\\n\\r]+?([\\d\\.]+)(\\s+or\\s+higher)?/i'; $matcherBundled = '/\\bgd\\s+version\\b[^\\d\\n\\r]+?bundled/i'; ob_end_clean(); } if (preg_match($matcherVersion, $matchString, $matches)) { $gdVersion = $matches[1]; } else { $gdVersion = 0; } if (isset($matches[2])) { $gdVersion = sprintf('>%s', $gdVersion); } $isGdBundled = 0; if (preg_match($matcherBundled, $matchString)) { $isGdBundled = 1; } /* Find out supported mime types */ $mimeChecks = array(array('mimeType' => 'image/gif', 'value' => defined('IMG_GIF') ? IMG_GIF : '', 'functions' => array('imageCreateFromGif', 'imageGif')), array('mimeType' => 'image/jpeg', 'value' => defined('IMG_JPEG') ? IMG_JPEG : '', 'functions' => array('imageCreateFromJpeg', 'imageJpeg')), array('mimeType' => 'image/png', 'value' => defined('IMG_PNG') ? IMG_PNG : '', 'functions' => array('imageCreateFromPng', 'imagePng')), array('mimeType' => 'image/vnd.wap.wbmp', 'value' => defined('IMG_WBMP') ? IMG_WBMP : '', 'functions' => array('imageCreateFromWbmp', 'imageWbmp')), array('mimeType' => 'image/x-xpixmap', 'value' => defined('IMG_XPM') ? IMG_XPM : '', 'functions' => array('imageCreateFromXpm', 'imageXpm')), array('mimeType' => 'image/x-xbitmap', 'value' => defined('IMG_XBM') ? IMG_XBM : '', 'functions' => array('imageCreateFromXbm', 'imageXbm'))); $mimeTypes = array(); foreach ($mimeChecks as $check) { $ok = true; foreach ($check['functions'] as $fct) { if (!function_exists($fct)) { $ok = false; } } if ($ok && !($check['value'] & imageTypes())) { $ok = false; } if ($ok) { $mimeTypes[] = $check['mimeType']; } } $out = ''; $out .= '$gdEnvironments[] = array(' . "\n"; $name = sprintf('%s|%s%s|%s', phpversion(), $gdVersion, $isGdBundled ? '-bundled' : '-external', PHP_OS); $out .= "\t" . sprintf('\'name\' => \'%s\',', $name) . "\n"; $out .= "\t" . sprintf('\'phpVersion\' => \'%s\',', phpversion()) . "\n"; $out .= "\t" . sprintf('\'gdVersion\' => \'%s\',', $gdVersion) . "\n"; $out .= "\t" . sprintf('\'gdBundled\' => %s,', $isGdBundled) . "\n"; $imageTypes = 0; if (function_exists('imageTypes')) { $imageTypes = imageTypes(); } $out .= "\t" . sprintf('\'imageTypes\' => %s,', $imageTypes) . "\n"; if (function_exists('gd_info')) { $gdInfo = gd_info(); $out .= "\t" . '\'gd_info\' => array(' . "\n"; foreach ($gdInfo as $field => $value) { $out .= "\t\t" . sprintf('\'%s\' => \'%s\',', $field, $value) . "\n"; } $out .= "\t" . '),' . "\n"; } /* Check which constants are defined */ $constants = get_defined_constants(); $out .= "\t" . '\'constants\' => array(' . "\n"; foreach ($constants as $constant => $value) { if (!preg_match('/^(IMAGE|IMG|GD|PHP)/', $constant)) { continue; } if (!is_int($value)) { $value = sprintf('\'%s\'', $value); } $out .= "\t\t" . sprintf('\'%s\' => %s,', $constant, $value) . "\n"; } $out .= "\t" . '),' . "\n"; $out .= "\t" . '\'mimeTypes\' => array(' . "\n"; foreach ($mimeTypes as $mimeType) { $out .= "\t\t" . sprintf('\'%s\',', $mimeType) . "\n"; } $out .= "\t" . '),' . "\n"; ob_start(); phpinfo(8); $phpinfo = ob_get_contents(); ob_end_clean(); $phpinfo = htmlspecialchars($phpinfo); $phpinfo = preg_replace('/\'/', '\\\'', $phpinfo); $out .= "\t" . sprintf('\'phpinfo(8)\' => \'%s\',', $phpinfo) . "\n"; /* Functions defined in this GD module */ $functions = get_extension_funcs('gd'); $out .= "\t" . '\'functions\' => array(' . "\n"; foreach ($functions as $fct) { $out .= "\t\t" . sprintf('\'%s\' => true,', $fct) . "\n"; } $otherFunctions = array('getimagesize', 'image_type_to_extension', 'image_type_to_mime_type', 'iptcembed', 'iptcparse'); foreach ($otherFunctions as $fct) { if (!function_exists($fct)) { continue; } $out .= "\t\t" . sprintf('\'%s\' => true,', $fct) . "\n"; } $out .= "\t" . '),' . "\n"; $out .= ');' . "\n"; return $out; }