3 include_once('./config/site.inc.php');
5 $request__ix = check_request('ix',CV_MD5 ,'');
6 $request__pg = check_request('pg',CV_DIGIT,0);
8 $fid_index = PATH_CACHE.'/'.$request__ix.CACHE_EXT_INDEX;
9 $fid_list = PATH_CACHE.'/'.$request__ix.CACHE_EXT_LIST;
11 if (!file_exists($fid_index)) {
12 die('error:ix not found');
15 $path = file_get_contents($fid_index);
16 $fid_comic = PATH_COMIC.'/'.$path;
18 if ($request__ix=='') {
19 die('error:empty ix');
23 // zipファイルのエントリリストを取得(画像ファイルに限定)
24 if (!file_exists($fid_list) || true) {
25 $entry_data = array();
26 $entry_name = array();
27 $zip = zip_open($fid_comic);
29 $img = array(NULL,NULL);
30 while(($zip_entry = zip_read($zip)) !== false){
32 $zip_entry_name = zip_entry_name($zip_entry);
33 $zip_entry_type = common__get_fileext($zip_entry_name);
34 if ($zip_entry_type=='' || mb_strpos('jpg/jpeg/png/gif',$zip_entry_type)===false) continue;
35 $entry_data[] = array(
37 'name' => $zip_entry_name,
38 'size' => zip_entry_filesize($zip_entry),
40 $entry_name[] = $zip_entry_name;
43 array_multisort($entry_name, SORT_ASC, $entry_data);
44 file_put_contents($fid_list,serialize($entry_data));
46 $entry_data = unserialize(file_get_contents($fid_list));
50 $zip_no[0] = isset($entry_data[$request__pg ]) ? $entry_data[$request__pg ]['no'] : -1;
51 $zip_no[1] = isset($entry_data[$request__pg+1]) ? $entry_data[$request__pg+1]['no'] : -1;
53 // zipファイルから指定されたページとその次ページを持ってくる
54 $zip = zip_open($fid_comic);
56 $img = array(NULL,NULL);
57 while(($zip_entry = zip_read($zip)) !== false){
58 foreach ($zip_no as $pgid => $target_no) {
59 if ($no==$target_no) {
60 $img[$pgid] = zip_entry_read($zip_entry,zip_entry_filesize($zip_entry));
63 if (!is_null($img[0]) && !is_null($img[1])) break;
70 if (is_null($img[0])) {
75 } else if (is_null($img[1])) {
78 header("Content-type: image/jpeg");
86 for ($pgid=0;$pgid<=1;$pgid++) {
87 $img[$pgid] = imagecreatefromstring($img[$pgid]);
88 $sx[$pgid] = imagesx($img[$pgid]);
89 $sy[$pgid] = imagesy($img[$pgid]);
93 if ($sx[0]>$sy[0] || $sx[1]>$sy[1]) {
94 // 横長ページが含まれるときは、1ページ目のみを戻す
95 header("Content-type: image/jpeg");
100 $vy = ($sy[0]>$sy[1] ? $sy[0] : $sy[1]);
101 $view = imagecreatetruecolor($vx,$vy);
102 header("Content-type: image/jpeg");
103 imagecopy($view,$img[0],$sx[1],($vy-$sy[0])/2,0,0,$sx[0],$sy[0]);
104 imagecopy($view,$img[1],0,($vy-$sy[1])/2,0,0,$sx[1],$sy[1]);