Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 3293
Línea 99... Línea 99...
99
            return false;
99
            return false;
100
        }
100
        }
101
    }*/
101
    }*/
Línea 102... Línea 102...
102
    
102
    
-
 
103
    /**
-
 
104
     *
-
 
105
     * @param string $source
-
 
106
     * @param string $target_path
-
 
107
     * @param string $target_filename
-
 
108
     * @param number $target_width
-
 
109
     * @param number $target_height
-
 
110
 
-
 
111
     * @return boolean
-
 
112
     */
-
 
113
    public  static function uploadImageWithoutCompletationSize($source, $target_path, $target_filename, $target_width, $target_height)
-
 
114
    {
-
 
115
        
-
 
116
        
-
 
117
        
-
 
118
        try {
-
 
119
            $data = file_get_contents($source);
-
 
120
            $img = imagecreatefromstring($data);
-
 
121
            
-
 
122
            if(!file_exists($target_path)) {
-
 
123
                mkdir($target_path, 0755);
-
 
124
            }
-
 
125
            
-
 
126
            if($img) {
-
 
127
                list($source_width, $source_height) = getimagesize($source);
-
 
128
 
-
 
129
                 $width_ratio    = $target_width / $source_width;
-
 
130
                 $height_ratio   = $target_height / $source_height;
-
 
131
                 if($width_ratio > $height_ratio) {
-
 
132
                    $resized_width = $target_width;
-
 
133
                    $resized_height = $source_height * $width_ratio;
-
 
134
                 } else {
-
 
135
                    $resized_height = $target_height;
-
 
136
                    $resized_width = $source_width * $height_ratio;
-
 
137
                 }
-
 
138
                
-
 
139
                $resized_width = round($resized_width);
-
 
140
                $resized_height = round($resized_height);
-
 
141
 
-
 
142
                
-
 
143
                
-
 
144
                $new_image = imageCreateTrueColor($resized_width, $resized_height);
-
 
145
                imageAlphaBlending($new_image, False);
-
 
146
                imageSaveAlpha($new_image, True);
-
 
147
                $transparent = imageColorAllocateAlpha($new_image, 0, 0, 0, 127);
-
 
148
                imagefill($new_image, 0, 0, $transparent);
-
 
149
                imageCopyResampled($new_image, $img , 0, 0, 0, 0, $resized_width, $resized_height, $source_width, $source_height);
-
 
150
                
-
 
151
   
-
 
152
                $target = $target_path . DIRECTORY_SEPARATOR . $target_filename;
-
 
153
                if(file_exists($target)) {
-
 
154
                    @unlink($target);
-
 
155
                }
-
 
156
                
-
 
157
                
-
 
158
                imagepng($new_image, $target);
-
 
159
            }
-
 
160
            
-
 
161
            unlink($source);
-
 
162
            
-
 
163
            return true;
-
 
164
            
-
 
165
        }
-
 
166
        catch (\Throwable $e)
-
 
167
        {
-
 
168
            error_log($e->getTraceAsString());
-
 
169
            return false;
-
 
170
        }
-
 
171
    }
-
 
172
    
103
    /**
173
    /**
104
     * 
174
     * 
105
     * @param string $source
175
     * @param string $source
106
     * @param string $target_path
176
     * @param string $target_path
107
     * @param string $target_filename
177
     * @param string $target_filename