source: temp/trunk/data/class/SC_Image.php @ 9127

Revision 9127, 3.2 KB checked in by kakinaka, 20 years ago (diff)

blank

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2/*
3 * Copyright(c) 2000-2006 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7
8//---- ¥¢¥Ã¥×¥í¡¼¥É¥Õ¥¡¥¤¥ë²Ã¹©¥¯¥é¥¹(thumb.php¤È¥»¥Ã¥È¤Ç»ÈÍѤ¹¤ë)
9class SC_Image {
10   
11    var $tmp_dir;
12       
13    function SC_Image($tmp_dir) {
14        // ¥Ø¥Ã¥À¥Õ¥¡¥¤¥ëÆÉ¹þ
15        $include_dir = realpath(dirname( __FILE__));
16        require_once($include_dir . "/../lib/thumb.php");
17        if(!ereg("/$", $tmp_dir)) {
18            $this->tmp_dir = $tmp_dir . "/";
19        } else {
20            $this->tmp_dir = $tmp_dir;
21        }
22    }
23   
24    //--- °ì»þ¥Õ¥¡¥¤¥ëÀ¸À®(¥µ¥à¥Í¥¤¥ë²èÁüÀ¸À®ÍÑ)
25    function makeTempImage($keyname, $max_width, $max_height) {
26        // °ì°Õ¤ÊID¤ò¼èÆÀ¤¹¤ë¡£
27        $mainname = uniqid("").".";
28        // ³ÈÄ¥»Ò°Ê³°¤òÃÖ¤­´¹¤¨¤ë¡£
29        $newFileName = ereg_replace("^.*\.",$mainname, $_FILES[$keyname]['name']);
30        $result  = MakeThumb($_FILES[$keyname]['tmp_name'], $this->tmp_dir , $max_width, $max_height, $newFileName);
31        gfDebugLog($result);
32        return $newFileName;
33    }
34
35    //--- ¥Õ¥¡¥¤¥ë¤ò»ØÄêÊݸDIR¤Ø°Üư
36    function moveTempImage($filename, $save_dir) {
37        // ¥³¥Ô¡¼¸µ¥Õ¥¡¥¤¥ë¡¢¥³¥Ô¡¼Àè¥Ç¥£¥ì¥¯¥È¥ê¤¬Â¸ºß¤¹¤ë¾ì¹ç¤Ë¤Î¤ß¼Â¹Ô¤¹¤ë
38        if(file_exists($this->tmp_dir.$filename) && file_exists($save_dir)) {
39            if(copy($this->tmp_dir . $filename , $save_dir."/".$filename)) {
40                unlink( $this->tmp_dir . $filename );
41            }
42        } else {
43            gfDebugLog($this->tmp_dir.$filename."¤Î°Üư¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£");
44        }
45    }
46
47    //---- »ØÄê¥Õ¥¡¥¤¥ë¤òºï½ü   
48    function deleteImage($filename, $dir) {
49        if(file_exists($dir."/".$filename)) {
50            unlink($dir."/".$filename);
51        }
52    }
53
54    // ³ÈÂçΨ¤ò»ØÄꤷ¤Æ²èÁüÊݸ
55    function saveResizeImage($file, $zip_scale = 1) {
56        // ¥Ç¥£¥ì¥¯¥È¥ê¼èÆÀ
57        $dir = dirname($file);
58       
59        // ¸µ²èÁü¥µ¥¤¥º¤ò¼èÆÀ
60        list($src_w, $src_h) = getimagesize($file);
61   
62        // °µ½ÌΨ»ØÄê
63        $zip_width = $src_w * $zip_scale;
64        $zip_height = $src_h * $zip_scale;
65       
66        // ¥Õ¥¡¥¤¥ë¤Î³ÈÄ¥»Ò¼èÆÀ
67        $arrFileInfo = pathinfo($file);
68        $extension = $arrFileInfo["extension"];
69
70        // °ì°Õ¤ÊID¤ò¼èÆÀ¤¹¤ë¡£
71        $uniqname = date("mdHi") . "_" . uniqid("");
72       
73        // ¥Õ¥¡¥¤¥ë̾¡¢ÊݸÀèÀßÄê
74        $filename = $uniqname . "." . $extension;
75        $path = $dir . "/" . $filename;
76
77        // ¥Õ¥¡¥¤¥ë¤Î³ÈÄ¥»Ò¤Ë¤è¤Ã¤Æ½èÍý¤òʬ¤±¤ë
78        if(is_dir($dir)) {
79            switch ($extension) {
80                case "jpg":
81                case "jpeg":
82                    //¸µ²èÁü
83                    $src_im = ImageCreateFromJPEG($file);
84                   
85                    // °µ½ÌÀè²èÁü
86                    $dst_im = imagecreatetruecolor($zip_width, $zip_height);   
87                    imagecopyresampled($dst_im, $src_im, 0, 0, 0,0, $zip_width, $zip_height, $src_w, $src_h);
88                   
89                    ImageJPEG($dst_im, $path);
90                    break;
91                case "gif":
92                    //¸µ²èÁü
93                    $src_im = ImageCreateFromGIF($file);
94                   
95                    // °µ½ÌÀè²èÁü
96                    $dst_im = imagecreatetruecolor($zip_width, $zip_height);   
97                    imagecopyresampled($dst_im, $src_im, 0, 0, 0,0, $zip_width, $zip_height, $src_w, $src_h);
98                   
99                    ImageGIF($dst_im, $path);
100                    break;
101                case "png":
102                    //¸µ²èÁü
103                    $src_im = ImageCreateFromPNG($file);
104                   
105                    // °µ½ÌÀè²èÁü
106                    $dst_im = imagecreatetruecolor($zip_width, $zip_height);   
107                    imagecopyresampled($dst_im, $src_im, 0, 0, 0,0, $zip_width, $zip_height, $src_w, $src_h);
108                   
109                    ImagePNG($dst_im, $path);
110                    break;
111                default:
112                    print("³ÈÄ¥»Ò¤¬ÉÔÀµ¤Ç¤¹¡£");
113                    $path = "";
114                    break;
115            }
116            ImageDestroy($src_im);
117            ImageDestroy($dst_im);
118            return $path;
119        }
120       
121        print("²èÁü¤ÎÊݸ¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£");
122        return "";
123    }
124}
125?>
Note: See TracBrowser for help on using the repository browser.