Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 1 Rev 15077
Línea 268... Línea 268...
268
        {
268
        {
269
            error_log($e->getTraceAsString());
269
            error_log($e->getTraceAsString());
270
            return false;
270
            return false;
271
        }
271
        }
272
    }
272
    }
-
 
273
    
-
 
274
    /**
-
 
275
     *
-
 
276
     * @param string $source
-
 
277
     * @param string $target_path
-
 
278
     * @param string $target_filename
-
 
279
     * @param number $target_width
-
 
280
     * @param number $target_height
-
 
281
     
-
 
282
     * @return boolean
-
 
283
     */
-
 
284
    public  static function uploadImageWithoutCompletationSize($source, $target_path, $target_filename, $target_width, $target_height)
-
 
285
    {
-
 
286
        
-
 
287
        
-
 
288
        
-
 
289
        try {
-
 
290
            $data = file_get_contents($source);
-
 
291
            $img = imagecreatefromstring($data);
-
 
292
            
-
 
293
            if(!file_exists($target_path)) {
-
 
294
                mkdir($target_path, 0755);
-
 
295
            }
-
 
296
            
-
 
297
            if($img) {
-
 
298
                list($source_width, $source_height) = getimagesize($source);
-
 
299
                
-
 
300
                $width_ratio    = $target_width / $source_width;
-
 
301
                $height_ratio   = $target_height / $source_height;
-
 
302
                if($width_ratio > $height_ratio) {
-
 
303
                    $resized_width = $target_width;
-
 
304
                    $resized_height = $source_height * $width_ratio;
-
 
305
                } else {
-
 
306
                    $resized_height = $target_height;
-
 
307
                    $resized_width = $source_width * $height_ratio;
-
 
308
                }
-
 
309
                
-
 
310
                $resized_width = round($resized_width);
-
 
311
                $resized_height = round($resized_height);
-
 
312
                
-
 
313
                
-
 
314
                
-
 
315
                $new_image = imageCreateTrueColor($resized_width, $resized_height);
-
 
316
                imageAlphaBlending($new_image, False);
-
 
317
                imageSaveAlpha($new_image, True);
-
 
318
                $transparent = imageColorAllocateAlpha($new_image, 0, 0, 0, 127);
-
 
319
                imagefill($new_image, 0, 0, $transparent);
-
 
320
                imageCopyResampled($new_image, $img , 0, 0, 0, 0, $resized_width, $resized_height, $source_width, $source_height);
-
 
321
                
-
 
322
                
-
 
323
                $target = $target_path . DIRECTORY_SEPARATOR . $target_filename;
-
 
324
                if(file_exists($target)) {
-
 
325
                    @unlink($target);
-
 
326
                }
-
 
327
                
-
 
328
                
-
 
329
                imagepng($new_image, $target);
-
 
330
            }
-
 
331
            
-
 
332
            unlink($source);
-
 
333
            
-
 
334
            return true;
-
 
335
            
-
 
336
        }
-
 
337
        catch (\Throwable $e)
-
 
338
        {
-
 
339
            error_log($e->getTraceAsString());
-
 
340
            return false;
-
 
341
        }
-
 
342
    }
Línea 273... Línea 343...
273
 
343
 
274
    /**
344
    /**
275
     * 
345
     * 
276
     * @param string $path
346
     * @param string $path