Changeset 18145
- Timestamp:
- 2009/06/29 15:32:01 (14 years ago)
- Location:
- branches/version-2_4/data
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_4/data/class/SC_MobileImage.php
r18006 r18145 69 69 if ($carrier == "docomo" or $carrier == "softbank") { 70 70 if( $result != false && $result > 0){ 71 72 73 74 75 76 71 // 計算式:(利用端末で表示可能なcacheサイズ - HTMLのバイト数 - 変換後の画像名のバイト数(目安値) ) / HTML中の画像数 72 $temp_imagefilesize = ($cacheSize - strlen($buffer) - (140 * $result) ) / $result; 73 } else { 74 // 計算式:(利用端末で表示可能なcacheサイズ - HTMLのバイト数 ) 75 $temp_imagefilesize = ($cacheSize - strlen($buffer) ); 76 } 77 77 // 計算結果が端末の表示可能ファイルサイズ上限より小さい場合は計算結果の値を有効にする 78 78 if ($temp_imagefilesize < $imageFileSize) { -
branches/version-2_4/data/include/image_converter.inc
r18009 r18145 4 4 */ 5 5 class ImageConverter { 6 var $outputImageDir;// 変換後の画像の保存先7 var $outputImageType;// 変換後の画像の形式8 var $outputImageWidth;// 変換後の画像の横幅9 var $outputImageHeight;// 変換後の画像の高さ10 var $outputImageFileSize;// 変換後の画像のファイルサイズ6 var $outputImageDir; // 変換後の画像の保存先 7 var $outputImageType; // 変換後の画像の形式 8 var $outputImageWidth; // 変換後の画像の横幅 9 var $outputImageHeight; // 変換後の画像の高さ 10 var $outputImageFileSize; // 変換後の画像のファイルサイズ 11 11 12 13 14 15 16 17 18 19 12 // コンストラクタ 13 function ImageConverter() { 14 $this->outputImageDir = realpath(realpath(dirname(__FILE__))); 15 $this->outputImageType = 'jpeg'; 16 $this->outputImageWidth = 320; 17 $this->outputImageHeight = NULL; 18 $this->outputFileSize = 20000; 19 } 20 20 21 22 23 24 25 26 27 28 29 30 21 // 変換実行 22 function execute($inputImagePath) { 23 // 前処理 24 $filestat = @stat($inputImagePath); 25 $imagesize = getimagesize($inputImagePath); 26 $inputImageWidth = $imagesize[0]; 27 $inputImageHeight = $imagesize[1]; 28 $inputImageType = $imagesize[2]; 29 $outputImageName = sha1($inputImagePath . '_' . $this->outputImageWidth . '_' . $this->outputFileSize . '_' . $filestat['mtime']) . '.' . $this->outputImageType; 30 $outputImagePath = $this->outputImageDir . '/' . $outputImageName; 31 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 32 if (is_null($this->outputImageHeight)) { 33 $height_was_null = TRUE; 34 $this->outputImageHeight = $inputImageHeight * ($this->outputImageWidth / $inputImageWidth); 35 } else { 36 $height_was_null = FALSE; 37 } 38 if ($inputImageWidth <= $this->outputImageWidth) { 39 if ($inputImageHeight <= $this->outputImageHeight) { 40 $this->outputImageWidth = $inputImageWidth; 41 $this->outputImageHeight = $inputImageHeight; 42 } else { 43 $this->outputImageWidth = $inputImageWidth * ($this->outputImageHeight / $inputImageHeight); 44 } 45 } else { 46 if ($inputImageHeight <= $this->outputImageHeight) { 47 $this->outputImageHeight = $inputImageHeight * ($this->outputImageWidth / $inputImageWidth); 48 } else { 49 if ($this->outputImageWidth / $inputImageWidth < $this->outputImageHeight / $inputImageHeight) { 50 $this->outputImageHeight = $inputImageHeight * ($this->outputImageWidth / $inputImageWidth); 51 } else { 52 $this->outputImageWidth = $inputImageWidth * ($this->outputImageHeight / $inputImageHeight); 53 } 54 } 55 } 56 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 57 // ファイルが存在するか確認し、存在しない場合のみ作成する 58 if (file_exists($outputImagePath)) { 59 $info['convert'] = FALSE; 60 } else { 61 // 元ファイル作成 62 switch($inputImageType) { 63 case 1: 64 // gif 65 $tempImage = imagecreatefromgif($inputImagePath); 66 break; 67 case 2: 68 // jpeg 69 $tempImage = imagecreatefromjpeg($inputImagePath); 70 break; 71 case 3: 72 // png 73 $tempImage = imagecreatefrompng($inputImagePath); 74 break; 75 case 6: 76 // bmp 77 $tempImage = imagecreatefromwbmp($inputImagePath); 78 break; 79 } 80 80 81 82 83 81 if (!$tempImage) { 82 return false; 83 } 84 84 85 86 87 88 89 90 85 $scale = 1.0; 86 $outputImagePathTemp = $outputImagePath . '.tmp-' . rand(); 87 do { 88 // 空ファイル作成 89 $outputImage = ImageCreateTruecolor($this->outputImageWidth * $scale, $this->outputImageHeight * $scale); 90 ImageCopyResampled($outputImage, $tempImage, 0, 0, 0, 0, $this->outputImageWidth * $scale, $this->outputImageHeight * $scale, $inputImageWidth, $inputImageHeight); 91 91 92 92 // ファイル出力 93 93 94 94 @unlink($outputImagePathTemp); 95 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 96 switch ($this->outputImageType) { 97 case 1: 98 case 'gif': 99 imagegif($outputImage, $outputImagePathTemp); 100 break; 101 default: 102 case 2: 103 case 'jpg': 104 case 'jpeg': 105 $quality = 75; 106 // 表示可能なファイルサイズ以下になるまで、10%ずつクオリティを調整する 107 do { 108 @unlink($outputImagePathTemp); 109 imagejpeg($outputImage, $outputImagePathTemp, $quality); 110 $quality -= 10; 111 clearstatcache(); 112 } while (filesize($outputImagePathTemp) > $this->outputFileSize && $quality > 0); 113 break; 114 case 3: 115 case 'png': 116 imagepng($outputImage, $outputImagePathTemp); 117 break; 118 case 6: 119 case 'bmp': 120 imagewbmp($outputImage, $outputImagePathTemp); 121 break; 122 } 123 123 124 125 124 // メモリ開放 125 imagedestroy($outputImage); 126 126 127 128 129 127 $scale -= 0.1; 128 clearstatcache(); 129 } while (filesize($outputImagePathTemp) > $this->outputFileSize && $scale >= 0.5); 130 130 131 131 rename($outputImagePathTemp, $outputImagePath); 132 132 133 134 133 // メモリ開放 134 imagedestroy($tempImage); 135 135 136 137 136 $info['convert'] = TRUE; 137 } 138 138 139 140 141 139 if ($height_was_null) { 140 $this->outputImageHeigh = NULL; 141 } 142 142 143 144 145 143 $info['outputImagePath'] = $outputImagePath; 144 $info['outputImageName'] = $outputImageName; 145 return $info; 146 146 147 147 } 148 148 149 150 151 152 153 154 149 // Setter 150 function setOutputDir($outputDir) { $this->outputImageDir = $outputDir; } 151 function setImageType($imageType) { $this->outputImageType = $imageType; } 152 function setImageWidth($imageWidth) { $this->outputImageWidth = $imageWidth; } 153 function setImageHeight($imageHeight) { $this->outputImageHeight = $imageHeight; } 154 function setFileSize($fileSize) { $this->outputFileSize = $fileSize; } 155 155 156 157 158 159 160 156 // Getter 157 function getOutputDir() { return $this->outputDir; } 158 function getImageType() { return $this->outputImageType; } 159 function getImageWidth() { return $this->outputImageWidth; } 160 function getImageHeight() { return $this->outputImageHeight; } 161 161 162 163 164 165 166 162 /* 163 * PrivateMethod 164 */ 165 function beforeExecute() { 166 } 167 167 } 168 168 ?>
Note: See TracChangeset
for help on using the changeset viewer.