Changeset 7551
- Timestamp:
- Jun 9, 2008, 5:03:37 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
OpenPNE/branches/work/ebihara/prj_renew_OpenPNE_Img/webapp/lib/OpenPNE/Img/Generator/ImageMagick.php
r7549 r7551 15 15 class OpenPNE_Img_Generator_ImageMagick extends OpenPNE_Img_Generator 16 16 { 17 var $raw_cache_fullpath; 18 17 19 function getCacheRawImage($filename) 18 20 { 19 $raw_cache_fullpath = $this->getRawCacheFileName($filename); 21 $this->setRawCacheFullPath($filename); 22 $raw_cache_fullpath = $this->getRawCacheFullPath(); 20 23 21 24 if (is_readable($raw_cache_fullpath)) { … … 33 36 * RAW画像キャッシュのファイルパスを設定する 34 37 */ 35 function getRawCacheFileName($filename)38 function setRawCacheFullPath($filename) 36 39 { 37 40 $prefix = OPENPNE_IMG_CACHE_PREFIX; … … 41 44 $path = sprintf('%s/w_h_raw/%s', $format, $file); 42 45 43 return $this->cache_dir . '/' . $path; 46 $this->raw_cache_fullpath = $this->cache_dir . '/' . $path; 47 } 48 49 function getRawCacheFullPath() 50 { 51 return $this->raw_cache_fullpath; 52 } 53 54 function createRawCache($raw_img) 55 { 56 $raw_cache_fullpath = $this->getRawCacheFullPath(); 57 $subdir = dirname($raw_cache_fullpath); 58 if (!is_dir($subdir)) { 59 mkdir($subdir); 60 } 61 62 if ($this->output_format == 'png') { 63 touch($raw_cache_fullpath); 64 $output_gdimg = imagecreatefromstring($raw_img); 65 imagepng($output_gdimg, $raw_cache_fullpath); 66 } else { 67 $handle = fopen($raw_cache_fullpath, 'wb'); 68 fwrite($handle, $raw_img); 69 fclose($handle); 70 } 71 } 72 73 function resizeImage($raw_img) 74 { 75 $this->createRawCache($raw_img); 76 77 return $this->execImageMagickConvertCommand(); 78 } 79 80 function execImageMagickConvertCommand() 81 { 82 if (defined('IMGMAGICK_OPT') && IMGMAGICK_OPT) { 83 $opt = IMGMAGICK_OPT; 84 } else { 85 $opt = '-resize'; 86 } 87 88 $w = intval($this->width); 89 $h = intval($this->height); 90 $f = escapeshellcmd($this->getOutputFormat()); 91 $path = realpath($this->getRawCacheFullPath()); 92 93 $command = sprintf('%s %s %dx%d %s %s:-', IMGMAGICK_APP, $opt, $w, $h, $path, $f); 94 95 while (@ob_end_clean()); 96 ob_start(); 97 passthru($command); 98 $output_img = ob_get_contents(); 99 while (@ob_end_clean()); 100 101 return $output_img; 102 } 103 104 function createCache($output_img) 105 { 106 if ($this->getOutputFormat() == 'png' && !$this->width && !$this->height) { 107 touch($this->cache_fullpath); 108 imagepng($output_img, $this->cache_fullpath); 109 return true; 110 } 111 112 $file = fopen($this->cache_fullpath, "wb"); 113 fwrite($file, $output_img); 114 fclose($file); 44 115 } 45 116 }
Note: See TracChangeset
for help on using the changeset viewer.