Code Duplication    Length = 39-40 lines in 2 locations

class/SwUploadHandler.php 1 location

@@ 74-113 (lines=40) @@
71
     * @param $file_name
72
     * @return bool
73
     */
74
    private function create_thumbnail($file_name)
75
    {
76
        $file_path      = $this->upload_dir . $file_name;
77
        $thumbnail_path = $this->thumbnails_dir . $file_name;
78
        list($img_width, $img_height) = @getimagesize($file_path);
79
        if (!$img_width || !$img_height) {
80
            return false;
81
        }
82
        $scale = min($this->thumbnail_max_width / $img_width, $this->thumbnail_max_height / $img_height);
83
        if ($scale > 1) {
84
            $scale = 1;
85
        }
86
        $thumbnail_width  = $img_width * $scale;
87
        $thumbnail_height = $img_height * $scale;
88
        $thumbnail_img    = @imagecreatetruecolor($thumbnail_width, $thumbnail_height);
89
        switch (mb_strtolower(mb_substr(mb_strrchr($file_name, '.'), 1))) {
90
            case 'jpg':
91
            case 'jpeg':
92
                $src_img         = @imagecreatefromjpeg($file_path);
93
                $write_thumbnail = 'imagejpeg';
94
                break;
95
            case 'gif':
96
                $src_img         = @imagecreatefromgif($file_path);
97
                $write_thumbnail = 'imagegif';
98
                break;
99
            case 'png':
100
                $src_img         = @imagecreatefrompng($file_path);
101
                $write_thumbnail = 'imagepng';
102
                break;
103
            default:
104
                $src_img = $write_thumbnail = null;
105
        }
106
        $success = $src_img && @imagecopyresampled($thumbnail_img, $src_img, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $img_width, $img_height)
107
                   && $write_thumbnail($thumbnail_img, $thumbnail_path);
108
        // Free up memory (imagedestroy does not delete files):
109
        @imagedestroy($src_img);
110
        @imagedestroy($thumbnail_img);
111
112
        return $success;
113
    }
114
115
    //function to return file extension from a path or file name
116

class/uploadclass.php 1 location

@@ 69-107 (lines=39) @@
66
     * @param $file_name
67
     * @return bool
68
     */
69
    private function create_thumbnail($file_name)
70
    {
71
        $file_path      = $this->upload_dir . $file_name;
72
        $thumbnail_path = $this->thumbnails_dir . $file_name;
73
        list($img_width, $img_height) = @getimagesize($file_path);
74
        if (!$img_width || !$img_height) {
75
            return false;
76
        }
77
        $scale = min($this->thumbnail_max_width / $img_width, $this->thumbnail_max_height / $img_height);
78
        if ($scale > 1) {
79
            $scale = 1;
80
        }
81
        $thumbnail_width  = $img_width * $scale;
82
        $thumbnail_height = $img_height * $scale;
83
        $thumbnail_img    = @imagecreatetruecolor($thumbnail_width, $thumbnail_height);
84
        switch (strtolower(substr(strrchr($file_name, '.'), 1))) {
85
            case 'jpg':
86
            case 'jpeg':
87
                $src_img         = @imagecreatefromjpeg($file_path);
88
                $write_thumbnail = 'imagejpeg';
89
                break;
90
            case 'gif':
91
                $src_img         = @imagecreatefromgif($file_path);
92
                $write_thumbnail = 'imagegif';
93
                break;
94
            case 'png':
95
                $src_img         = @imagecreatefrompng($file_path);
96
                $write_thumbnail = 'imagepng';
97
                break;
98
            default:
99
                $src_img = $write_thumbnail = null;
100
        }
101
        $success = $src_img && @imagecopyresampled($thumbnail_img, $src_img, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $img_width, $img_height)
102
                   && $write_thumbnail($thumbnail_img, $thumbnail_path);
103
        // Free up memory (imagedestroy does not delete files):
104
        @imagedestroy($src_img);
105
        @imagedestroy($thumbnail_img);
106
        return $success;
107
    }
108
109
    //function to return file extension from a path or file name
110