/** * コンストラクタ * * @param int $mode * @param array $dynamic_options */ public function __construct($mode = self::SIZE_DEFAULT, array $dynamic_options = null) { if ($dynamic_options) { $options = array_merge($this->default_options, $dynamic_options); $this->dynamic = true; $this->intermd = $options['intermd']; } else { $options = $this->default_options; $this->dynamic = false; $this->intermd = false; } // 設定 $this->ini = ic2_loadconfig(); // データベースに接続 $icdb = new IC2_DataObject_Images(); $this->db = $icdb->getDatabaseConnection(); if (DB::isError($this->db)) { $this->error($this->db->getMessage()); } // サムネイルモード判定 $dpr = $mode & self::DPR_MASK; $mode = $mode & ~self::DPR_MASK; if ($dpr === self::DPR_1_5 || $dpr === self::DPR_2_0) { $this->dpr = $dpr; } else { $this->dpr = $dpr = self::DPR_DEFAULT; } switch ($mode) { case self::SIZE_SOURCE: case self::SIZE_PC: $this->mode = self::SIZE_PC; $setting = $this->ini['Thumb1']; break; case self::SIZE_MOBILE: $this->mode = self::SIZE_MOBILE; $setting = $this->ini['Thumb2']; break; case self::SIZE_INTERMD: $this->mode = self::SIZE_INTERMD; $setting = $this->ini['Thumb3']; break; default: $this->error('無効なサムネイルモードです。'); } // イメージドライバ判定 $driver = strtolower($this->ini['General']['driver']); $this->driver = $driver; switch ($driver) { case 'imagemagick6': // ImageMagick6 の convert コマンド $this->driver = 'imagemagick'; case 'imagemagick': // ImageMagick の convert コマンド $searchpath = $this->ini['General']['magick']; if (!ic2_findexec('convert', $searchpath)) { $this->error('ImageMagickが使えません。'); } if ($searchpath) { $this->magick = $searchpath . DIRECTORY_SEPARATOR . 'convert'; } else { $this->magick = 'convert'; } break; case 'gd': // PHP の GD 拡張機能 // PHP の GD 拡張機能 case 'imagick': // PHP の ImageMagick 拡張機能 // PHP の ImageMagick 拡張機能 case 'imlib2': // PHP の Imlib2 拡張機能 if (!extension_loaded($driver)) { $this->error($driver . 'エクステンションが使えません。'); } break; default: $this->error('無効なイメージドライバです。'); } // ディレクトリ設定 $this->cachedir = $this->ini['General']['cachedir']; $this->sourcedir = $this->cachedir . '/' . $this->ini['Source']['name']; $this->thumbdir = $this->cachedir . '/' . $setting['name']; // サムネイルの画像形式・幅・高さ・回転角度・品質設定 $rotate = (int) $options['rotate']; if (abs($rotate) < 4) { $rotate = $rotate * 90; } $rotate = $rotate < 0 ? $rotate % 360 + 360 : $rotate % 360; $this->rotate = $rotate % 90 == 0 ? $rotate : 0; if ($options['width'] >= 1 && $options['height'] >= 1) { $setting['width'] = $options['width']; $setting['height'] = $options['height']; } if ($this->rotate % 180 == 90) { $this->max_width = (int) $setting['height']; $this->max_height = (int) $setting['width']; } else { $this->max_width = (int) $setting['width']; $this->max_height = (int) $setting['height']; } if (is_null($options['quality'])) { $this->quality = (int) $setting['quality']; } else { $this->quality = (int) $options['quality']; } if (0 < $this->quality && $this->quality <= 100) { $this->type = '.jpg'; } else { $this->type = '.png'; $this->quality = 0; } $this->trim = (bool) $options['trim']; // Epeg使用判定 if ($this->ini['General']['epeg'] && extension_loaded('epeg') && !$this->dynamic && $this->type == '.jpg' && $this->quality <= $this->ini['General']['epeg_quality_limit']) { $this->epeg = true; } else { $this->epeg = false; } // サムネイルの背景色設定 if (preg_match('/^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i', $this->ini['General']['bgcolor'], $c)) { $r = hexdec($c[1]); $g = hexdec($c[2]); $b = hexdec($c[3]); } elseif (preg_match('/^#?([0-9A-F])([0-9A-F])([0-9A-F])$/i', $this->ini['General']['bgcolor'], $c)) { $r = hexdec($c[1] . $c[1]); $g = hexdec($c[2] . $c[2]); $b = hexdec($c[3] . $c[3]); } elseif (preg_match('/^(\\d{1,3}),(\\d{1,3}),(\\d{1,3})$/', $this->ini['General']['bgcolor'], $c)) { $r = max(0, min(intval($c[1]), 255)); $g = max(0, min(intval($c[2]), 255)); $b = max(0, min(intval($c[3]), 255)); } else { $r = null; $g = null; $b = null; } $this->bgcolor = array($r, $g, $b); }
if (!$fp) { ic2_error('x02', "fopen失敗。({$tmpfile})"); } fwrite($fp, $response['body']); fclose($fp); // }}} // {{{ check // ウィルススキャン if ($ini['Getter']['virusscan']) { $searchpath = $thumbnailer->ini['Getter']['clamav']; if ($ini['Getter']['virusscan'] == 2) { $clamscan = 'clamdscan'; } else { $clamscan = 'clamscan'; } if ($clamscan = ic2_findexec($clamscan, $searchpath)) { $scan_command = $clamscan . ' --stdout ' . escapeshellarg(realpath($tmpfile)); $scan_result = @exec($scan_command, $scan_stdout, $scan_result); if ($scan_result == 1) { $params = array('uri' => $uri, 'host' => $pURL['host'], 'name' => basename($pURL['path']), 'size' => filesize($tmpfile), 'md5' => md5_file($tmpfile), 'width' => 0, 'height' => 0, 'mime' => 'clamscan/infected', 'memo' => $memo); ic2_aborn($params, true); ic2_error('x04', 'ウィルスを発見しました。'); } } } // 画像情報を調べる。MIMEタイプはサーバが送ってきたものを信頼しない。 $info = @getimagesize($tmpfile); if (!$info) { ic2_error('x02', '画像サイズの取得に失敗しました。'); } elseif (!isset($info['mime'])) { // < PHP4.3.0
/** * @return bool */ private function checkConfiguration() { $result = true; $enabled = $GLOBALS['_conf']['expack.ic2.enabled']; $dsn = $this->config['General']['dsn']; $driver = $this->config['General']['driver']; $this->comment('enabled=' . var_export($enabled, true)); $this->comment('dsn=' . var_export($dsn, true)); $this->comment('driver=' . var_export($driver, true)); if (!$enabled) { $this->error("\$_conf['expack.ic2.enabled'] is not enabled in conf/conf_admin_ex.inc.php."); $result = false; } if (!$dsn) { $this->error("\$_conf['expack.ic2.general.dsn'] is not set in conf/conf_ic2.inc.php."); $result = false; } $driver = strtolower($driver); switch ($driver) { case 'imagemagick6': case 'imagemagick': if (!ic2_findexec('convert', $this->config['General']['magick'])) { $this->error("Command 'convert' is not found"); $result = false; } else { $this->info('Image Driver: OK'); } break; case 'gd': case 'imagick': case 'imlib2': if (!extension_loaded($driver)) { $this->error("Extension {$driver} is not loaded"); $result = false; } else { $this->info('Image Driver: OK'); } break; default: $this->error('Unknow image driver.'); $result = false; } return $result; }