Proyectos de Subversion LeadersLinked - Services

Rev

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

Rev 552 Rev 553
Línea 328... Línea 328...
328
    public function composePathToFilename($type, $code, $filename)
328
    public function composePathToFilename($type, $code, $filename)
329
    {
329
    {
330
        $path = $this->getPathByType($type);
330
        $path = $this->getPathByType($type);
331
        $path = $path . DIRECTORY_SEPARATOR . $code;
331
        $path = $path . DIRECTORY_SEPARATOR . $code;
332
        if (! file_exists($path)) {
332
        if (! file_exists($path)) {
333
            @mkdir($path, 0775, true);
333
            mkdir($path, 0775, true);
334
        }
334
        }
335
        return $path . DIRECTORY_SEPARATOR . $filename;
335
        return $path . DIRECTORY_SEPARATOR . $filename;
336
    }
336
    }
Línea 337... Línea 337...
337
 
337
 
Línea 344... Línea 344...
344
    public function composePathToDirectory($type, $code)
344
    public function composePathToDirectory($type, $code)
345
    {
345
    {
346
        $path = $this->getPathByType($type);
346
        $path = $this->getPathByType($type);
347
        $path = $path . DIRECTORY_SEPARATOR . $code;
347
        $path = $path . DIRECTORY_SEPARATOR . $code;
348
        if (! file_exists($path)) {
348
        if (! file_exists($path)) {
349
            @mkdir($path, 0775, true);
349
            mkdir($path, 0775, true);
350
        }
350
        }
351
        return $path;
351
        return $path;
352
    }
352
    }
Línea 353... Línea 353...
353
 
353
 
-
 
354
    /**
354
    /**
355
     * Private helper to get a presigned URL for an entity's image/cover or its default.
-
 
356
     *
355
     *
357
     * @param string $entityType The type of the entity (e.g., self::TYPE_USER).
-
 
358
     * @param string $entityUuid The UUID of the entity.
-
 
359
     * @param string|null $imageFilename The filename of the image/cover, if it exists.
356
     * @param User $user
360
     * @param string $defaultImageMethodName The name of the method in this class to get the full path to the default image.
357
     * @return string
361
     * @return string The presigned URL.
358
     */
362
     */
359
    public function getUserImage($user)
363
    private function _getProcessedImageOrCoverUrl($entityType, $entityUuid, $imageFilename, $defaultImageMethodName)
360
    {
364
    {
361
        if ($user->image) {
365
        if ($imageFilename) {
362
            $remoto = $this->composePathToFilename(self::TYPE_USER, $user->uuid, $user->image);
366
            $remoto = $this->composePathToFilename($entityType, $entityUuid, $imageFilename);
363
            if (file_exists($remoto)) {
367
            if (file_exists($remoto)) {
364
                return $this->getPresignedUrl($remoto);
368
                return $this->getPresignedUrl($remoto);
365
            }
369
            }
-
 
370
        }
-
 
371
        // If imageFilename is null/empty, or the specific file doesn't exist, use the default.
-
 
372
        $defaultFullPath = $this->$defaultImageMethodName();
-
 
373
        return $this->getPresignedUrl($defaultFullPath);
Línea -... Línea 374...
-
 
374
    }
-
 
375
 
-
 
376
    /**
-
 
377
     *
-
 
378
     * @param User $user
366
        }
379
     * @return string
-
 
380
     */
367
 
381
    public function getUserImage($user)
368
        $remoto = $this->getFullPathImageUserDefault();
382
    {
Línea 369... Línea 383...
369
        return $this->getPresignedUrl($remoto);
383
        return $this->_getProcessedImageOrCoverUrl(self::TYPE_USER, $user->uuid, $user->image, 'getFullPathImageUserDefault');
370
    }
384
    }
371
 
385
 
372
    /**
386
    /**
373
     *
387
     *
374
     * @param User $user
388
     * @param User $user
375
     * @return string
389
     * @return string
376
     */
-
 
377
    public function getUserImageForCodeAndFilename($code, $filename)
390
     */
378
    {
-
 
379
        if ($filename) {
-
 
380
            $remoto = $this->composePathToFilename(self::TYPE_USER, $code, $filename);
-
 
381
            if (file_exists($remoto)) {
-
 
382
                return $this->getPresignedUrl($remoto);
-
 
383
            }
-
 
384
        }
391
    public function getUserImageForCodeAndFilename($code, $filename)
Línea 385... Línea 392...
385
        $remoto = $this->getFullPathImageUserDefault();
392
    {
386
        return $this->getPresignedUrl($remoto);
393
        return $this->_getProcessedImageOrCoverUrl(self::TYPE_USER, $code, $filename, 'getFullPathImageUserDefault');
387
    }
394
    }
388
 
395
 
389
    /**
396
    /**
390
     *
397
     *
391
     * @param User $user
398
     * @param User $user
392
     * @param UserProfile $userProfile
399
     * @param UserProfile $userProfile
393
     * @return string
-
 
394
     */
400
     * @return string
395
    public function getUserProfileImage($user, $userProfile)
-
 
396
    {
-
 
397
        if ($userProfile->image) {
-
 
398
            $remoto = $this->composePathToFilename(self::TYPE_USER, $user->uuid, $userProfile->image);
-
 
399
            if (file_exists($remoto)) {
-
 
400
                return $this->getPresignedUrl($remoto);
-
 
401
            }
-
 
402
        }
401
     */
Línea 403... Línea 402...
403
 
402
    public function getUserProfileImage($user, $userProfile)
404
        $remoto = $this->getFullPathImageUserPofileDefault();
403
    {
405
        return $this->getPresignedUrl($remoto);
404
        return $this->_getProcessedImageOrCoverUrl(self::TYPE_USER, $user->uuid, $userProfile->image, 'getFullPathImageUserPofileDefault');
406
    }
405
    }
407
 
406
 
408
    /**
407
    /**
409
     *
408
     *
410
     * @param User $user
409
     * @param User $user
411
     * @param UserProfile $userProfile
-
 
412
     * @return string
410
     * @param UserProfile $userProfile
413
     */
-
 
414
    public function getUserProfileCover($user, $userProfile)
-
 
415
    {
-
 
416
        if ($userProfile->cover) {
-
 
417
            $remoto = $this->composePathToFilename(self::TYPE_USER, $user->uuid, $userProfile->cover);
-
 
418
            if (file_exists($remoto)) {
-
 
419
                return $this->getPresignedUrl($remoto);
-
 
420
            }
411
     * @return string
Línea 421... Línea 412...
421
        }
412
     */
422
 
413
    public function getUserProfileCover($user, $userProfile)
423
        $remoto = $this->getFullPathImageUserCoverDefault();
414
    {
424
        return $this->getPresignedUrl($remoto);
415
        return $this->_getProcessedImageOrCoverUrl(self::TYPE_USER, $user->uuid, $userProfile->cover, 'getFullPathImageUserCoverDefault');
425
    }
416
    }
426
 
417
 
427
    /**
418
    /**
428
     *
-
 
429
     * @param Company $company
419
     *
430
     * @return string
-
 
431
     */
-
 
432
    public function getCompanyImage($company)
-
 
433
    {
-
 
434
        if ($company->image) {
-
 
435
            $remoto = $this->composePathToFilename(self::TYPE_COMPANY, $company->uuid, $company->image);
-
 
436
            if (file_exists($remoto)) {
-
 
437
                return $this->getPresignedUrl($remoto);
420
     * @param Company $company
Línea 438... Línea 421...
438
            }
421
     * @return string
439
        }
422
     */
440
 
423
    public function getCompanyImage($company)
441
        $remoto = $this->getFullPathImageCompanyDefault();
424
    {
442
        return $this->getPresignedUrl($remoto);
425
        return $this->_getProcessedImageOrCoverUrl(self::TYPE_COMPANY, $company->uuid, $company->image, 'getFullPathImageCompanyDefault');
443
    }
426
    }
444
 
427
 
445
    /**
428
    /**
446
     *
-
 
447
     * @param string $code
429
     *
448
     * @param string $filename
-
 
449
     * @return string
-
 
450
     */
-
 
451
    public function getCompanyImageForCodeAndFilename($code, $filename)
-
 
452
    {
-
 
453
        if ($filename) {
-
 
454
            $remoto = $this->composePathToFilename(self::TYPE_COMPANY, $code, $filename);
-
 
455
            if (file_exists($remoto)) {
430
     * @param string $code
Línea 456... Línea 431...
456
                return $this->getPresignedUrl($remoto);
431
     * @param string $filename
457
            }
432
     * @return string
458
        }
433
     */
459
 
434
    public function getCompanyImageForCodeAndFilename($code, $filename)
460
        $remoto = $this->getFullPathImageCompanyDefault();
435
    {
461
        return $this->getPresignedUrl($remoto);
436
        return $this->_getProcessedImageOrCoverUrl(self::TYPE_COMPANY, $code, $filename, 'getFullPathImageCompanyDefault');
462
    }
437
    }
463
 
-
 
464
    /**
438
 
465
     *
-
 
466
     * @param Company $company
-
 
467
     * @return string
-
 
468
     */
-
 
469
    public function getCompanyCover($company)
-
 
470
    {
-
 
471
        if ($company->cover) {
-
 
472
            $remoto = $this->composePathToFilename(self::TYPE_COMPANY, $company->uuid, $company->cover);
439
    /**
Línea 473... Línea 440...
473
            if (file_exists($remoto)) {
440
     *
474
                return $this->getPresignedUrl($remoto);
441
     * @param Company $company
475
            }
442
     * @return string
476
        }
443
     */
477
 
444
    public function getCompanyCover($company)
478
        $remoto = $this->getFullPathImageCompanyCoverDefault();
445
    {
479
        return $this->getPresignedUrl($remoto);
446
        return $this->_getProcessedImageOrCoverUrl(self::TYPE_COMPANY, $company->uuid, $company->cover, 'getFullPathImageCompanyCoverDefault');
480
    }
-
 
481
 
447
    }
482
    /**
-
 
483
     *
-
 
484
     * @param Group $group
-
 
485
     * @return string
-
 
486
     */
-
 
487
    public function getGroupImage($group)
-
 
488
    {
-
 
489
        if ($group->image) {
448
 
Línea 490... Línea 449...
490
            $remoto = $this->composePathToFilename(self::TYPE_GROUP, $group->uuid, $group->image);
449
    /**
491
            if (file_exists($remoto)) {
450
     *
492
                return $this->getPresignedUrl($remoto);
451
     * @param Group $group
493
            }
452
     * @return string
494
        }
453
     */
495
 
454
    public function getGroupImage($group)
496
        $remoto = $this->getFullPathImageGroupDefault();
455
    {
497
        return $this->getPresignedUrl($remoto);
456
        return $this->_getProcessedImageOrCoverUrl(self::TYPE_GROUP, $group->uuid, $group->image, 'getFullPathImageGroupDefault');
498
    }
-
 
499
 
457
    }
500
    /**
-
 
501
     *
-
 
502
     * @param string $code
-
 
503
     * @param string $filename
-
 
504
     * @return string
-
 
505
     */
-
 
506
    public function getGroupImageForCodeAndFilename($code, $filename)
-
 
507
    {
458
 
Línea 508... Línea 459...
508
        if ($filename) {
459
    /**
509
            $remoto = $this->composePathToFilename(self::TYPE_COMPANY, $code, $filename);
460
     *
510
            if (file_exists($remoto)) {
461
     * @param string $code
511
                return $this->getPresignedUrl($remoto);
462
     * @param string $filename
512
            }
463
     * @return string
513
        }
464
     */
514
 
465
    public function getGroupImageForCodeAndFilename($code, $filename)
515
        $remoto = $this->getFullPathImageGroupDefault();
-
 
516
        return $this->getPresignedUrl($remoto);
466
    {
517
    }
-
 
518
 
-
 
519
    /**
-
 
520
     *
-
 
521
     * @param Group $group
-
 
522
     * @return string
-
 
523
     */
-
 
524
    public function getGroupCover($group)
467
        return $this->_getProcessedImageOrCoverUrl(self::TYPE_COMPANY, $code, $filename, 'getFullPathImageGroupDefault');
Línea 525... Línea 468...
525
    {
468
    }
526
        if ($group->cover) {
469
 
527
            $remoto = $this->composePathToFilename(self::TYPE_COMPANY, $group->uuid, $group->cover);
470
    /**
Línea 851... Línea 794...
851
     * @return string
794
     * @return string
852
     */
795
     */
853
    public function deleteFile($path, $code, $filename)
796
    public function deleteFile($path, $code, $filename)
854
    {
797
    {
855
        $remoto = $path . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR . $filename;
798
        $remoto = $path . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR . $filename;
856
        if (file_exists($filename)) {
799
        if (file_exists($remoto)) {
857
            return @unlink($remoto);
800
            return unlink($remoto);
858
        } else {
801
        } else {
859
            return true;
802
            return true;
860
        }
803
        }
861
    }
804
    }
Línea 890... Línea 833...
890
                if ($object != '.' && $object != '..') {
833
                if ($object != '.' && $object != '..') {
891
                    $s = $dir . DIRECTORY_SEPARATOR . $object;
834
                    $s = $dir . DIRECTORY_SEPARATOR . $object;
892
                    if (is_dir($s) && ! is_link($s)) {
835
                    if (is_dir($s) && ! is_link($s)) {
893
                        $this->deleteDirectoryRecursive($s);
836
                        $this->deleteDirectoryRecursive($s);
894
                    } else {
837
                    } else {
895
                        @unlink($s);
838
                        unlink($s);
896
                    }
839
                    }
897
                }
840
                }
898
            }
841
            }
899
            @rmdir($dir);
842
            rmdir($dir);
900
        }
843
        }
901
    }
844
    }
Línea 902... Línea 845...
902
 
845
 
903
    /**
846
    /**
Línea 907... Línea 850...
907
     * @param string $local_filename
850
     * @param string $local_filename
908
     * @return boolean
851
     * @return boolean
909
     */
852
     */
910
    public function putFile($source_file, $target_file)
853
    public function putFile($source_file, $target_file)
911
    {
854
    {
912
        return @rename($source_file, $target_file);
855
        return rename($source_file, $target_file);
913
    }
856
    }
Línea 914... Línea 857...
914
 
857
 
915
    /**
858
    /**
916
     *
859
     *
Línea 920... Línea 863...
920
     * @param string $filename
863
     * @param string $filename
921
     * @return boolean
864
     * @return boolean
922
     */
865
     */
923
    public function moveUploadedFile($source_file, $target_file)
866
    public function moveUploadedFile($source_file, $target_file)
924
    {
867
    {
925
        return @move_uploaded_file($source_file, $target_file);
868
        return move_uploaded_file($source_file, $target_file);
926
    }
869
    }
Línea 927... Línea 870...
927
 
870
 
928
    /**
871
    /**
929
     *
872
     *
Línea 933... Línea 876...
933
     * @param string $filename
876
     * @param string $filename
934
     * @return boolean
877
     * @return boolean
935
     */
878
     */
936
    public function copyFile($source_file, $target_file)
879
    public function copyFile($source_file, $target_file)
937
    {
880
    {
938
        return @copy($source_file, $target_file);
881
        return copy($source_file, $target_file);
939
    }
882
    }
Línea 940... Línea 883...
940
 
883
 
941
 
884
 
Línea 1045... Línea 988...
1045
            return;
988
            return;
1046
        }
989
        }
1047
    }
990
    }
Línea 1048... Línea 991...
1048
 
991
 
-
 
992
    /**
-
 
993
     * Creates a new GD image resource with transparency settings for PNG.
-
 
994
     * @param int $width The width of the new image.
-
 
995
     * @param int $height The height of the new image.
-
 
996
     * @return \GdImage|false The image resource or false on failure.
-
 
997
     */
-
 
998
    private function _createImageCanvas($width, $height)
-
 
999
    {
-
 
1000
        $new_image = imageCreateTrueColor($width, $height);
-
 
1001
        if ($new_image === false) {
-
 
1002
            error_log("_createImageCanvas: imageCreateTrueColor failed for dimensions {$width}x{$height}.");
-
 
1003
            return false;
-
 
1004
        }
-
 
1005
        imageAlphaBlending($new_image, False);
-
 
1006
        imageSaveAlpha($new_image, True);
-
 
1007
        $transparent = imageColorAllocateAlpha($new_image, 0, 0, 0, 127);
-
 
1008
        if ($transparent === false) {
-
 
1009
            error_log("_createImageCanvas: imageColorAllocateAlpha failed.");
-
 
1010
            imagedestroy($new_image);
-
 
1011
            return false;
-
 
1012
        }
-
 
1013
        imagefill($new_image, 0, 0, $transparent);
-
 
1014
        return $new_image;
-
 
1015
    }
-
 
1016
 
-
 
1017
    /**
-
 
1018
     * Saves a GD image resource as PNG, unlinks source, and cleans up image resource.
-
 
1019
     * @param \GdImage $imageResource The GD image resource to save.
-
 
1020
     * @param string $targetFilename The path to save the PNG file to.
-
 
1021
     * @param string $sourceFilenameToUnlink The path to the source file to unlink.
-
 
1022
     * @return bool True on success, false on failure.
-
 
1023
     */
-
 
1024
    private function _savePngAndCleanup($imageResource, $targetFilename, $sourceFilenameToUnlink)
-
 
1025
    {
-
 
1026
        $save_success = imagepng($imageResource, $targetFilename);
-
 
1027
        imagedestroy($imageResource); // Clean up the image resource
-
 
1028
 
-
 
1029
        if ($save_success) {
-
 
1030
            if ($sourceFilenameToUnlink && file_exists($sourceFilenameToUnlink)) {
-
 
1031
                unlink($sourceFilenameToUnlink);
-
 
1032
            }
-
 
1033
            return true;
-
 
1034
        } else {
-
 
1035
            error_log("_savePngAndCleanup: imagepng failed to save image to {$targetFilename}.");
-
 
1036
            return false;
-
 
1037
        }
-
 
1038
    }
-
 
1039
 
1049
    /**
1040
    /**
1050
     *
1041
     *
1051
     * @param string $source
1042
     * @param string $source
1052
     * @param string $target_filename
1043
     * @param string $target_filename
1053
     * @param number $target_width
1044
     * @param number $target_width
1054
     * @param number $target_height
1045
     * @param number $target_height
1055
     * @return boolean
1046
     * @return boolean
1056
     */
1047
     */
1057
    public function uploadImageResize($source_filename, $target_filename, $target_width, $target_height)
1048
    public function uploadImageResize($source_filename, $target_filename, $target_width, $target_height)
1058
    {
-
 
1059
 
1049
    {
1060
        try {
-
 
1061
 
1050
        try {
1062
            $data = file_get_contents($source_filename);
1051
            $data = file_get_contents($source_filename);
Línea 1063... Línea -...
1063
            $img = imagecreatefromstring($data);
-
 
1064
 
1052
            $img = imagecreatefromstring($data);
1065
 
1053
 
Línea 1066... Línea -...
1066
            if ($img) {
-
 
1067
                list($source_width, $source_height) = getimagesize($source_filename);
1054
            if ($img) {
1068
 
1055
                list($source_width, $source_height) = getimagesize($source_filename);
Línea 1069... Línea 1056...
1069
 
1056
 
1070
                $width_ratio = $target_width / $source_width;
1057
                $width_ratio = $target_width / $source_width;
Línea 1076... Línea 1063...
1076
                } else {
1063
                } else {
1077
                    $resized_height = $target_height;
1064
                    $resized_height = $target_height;
1078
                    $resized_width = $source_width * $height_ratio;
1065
                    $resized_width = $source_width * $height_ratio;
1079
                }
1066
                }
Línea 1080... Línea -...
1080
 
-
 
1081
 
-
 
1082
 
1067
 
1083
                $resized_width = round($resized_width);
1068
                $resized_width = round($resized_width);
Línea 1084... Línea 1069...
1084
                $resized_height = round($resized_height);
1069
                $resized_height = round($resized_height);
1085
 
1070
 
1086
                $new_image = imageCreateTrueColor($target_width, $target_height);
1071
                $new_image = $this->_createImageCanvas($target_width, $target_height);
1087
                imageAlphaBlending($new_image, False);
1072
                if ($new_image === false) {
1088
                imageSaveAlpha($new_image, True);
1073
                    imagedestroy($img);
1089
                $transparent = imageColorAllocateAlpha($new_image, 0, 0, 0, 127);
1074
                    unlink($source_filename);
1090
                imagefill($new_image, 0, 0, $transparent);
-
 
Línea -... Línea 1075...
-
 
1075
                    return false;
1091
                imageCopyResampled($new_image, $img, 0, 0, 0, 0, $resized_width, $resized_height, $source_width, $source_height);
1076
                }
Línea 1092... Línea 1077...
1092
 
1077
 
1093
 
-
 
1094
                imagepng($new_image, $target_filename);
1078
                imageCopyResampled($new_image, $img, 0, 0, 0, 0, $resized_width, $resized_height, $source_width, $source_height);
Línea 1095... Línea 1079...
1095
 
1079
                imagedestroy($img); // Source image resource can be destroyed after resampling
1096
                // @unlink($source_filename); // Temporarily commented out for debugging
1080
 
1097
                return true;
1081
                return $this->_savePngAndCleanup($new_image, $target_filename, $source_filename);
1098
            }
-
 
1099
 
1082
            }
-
 
1083
 
-
 
1084
            unlink($source_filename);
-
 
1085
            return false;
-
 
1086
        } catch (\Throwable $e) {
-
 
1087
            error_log($e->getTraceAsString());
1100
            // @unlink($source_filename); // Temporarily commented out for debugging
1088
            if (isset($img) && ($img instanceof \GdImage || is_resource($img))) {
1101
            return false;
1089
                imagedestroy($img);
-
 
1090
            }
-
 
1091
            if (isset($new_image) && ($new_image instanceof \GdImage || is_resource($new_image))) {
1102
        } catch (\Throwable $e) {
1092
                imagedestroy($new_image);
1103
            error_log('Error in uploadImageResize: ' . $e->getMessage() . ' at ' . $e->getFile() . ':' . $e->getLine()); // More detailed log
1093
            } 
1104
            error_log($e->getTraceAsString());
1094
            if (isset($source_filename) && file_exists($source_filename)) {
Línea 1118... Línea 1108...
1118
 
1108
 
1119
     * @return boolean
1109
     * @return boolean
1120
     */
1110
     */
1121
    public function uploadImageCrop($source_filename, $target_filename, $target_width, $target_height)
1111
    public function uploadImageCrop($source_filename, $target_filename, $target_width, $target_height)
1122
    {
-
 
1123
 
1112
    {
1124
        try {
-
 
1125
 
1113
        try {
1126
            $data = file_get_contents($source_filename);
1114
            $data = file_get_contents($source_filename);
Línea 1127... Línea -...
1127
            $img = imagecreatefromstring($data);
-
 
1128
 
1115
            $img = imagecreatefromstring($data);
1129
 
1116
 
Línea 1130... Línea 1117...
1130
            if ($img) {
1117
            if ($img) {
1131
                list($source_width, $source_height) = getimagesize($source_filename);
1118
                list($source_width, $source_height) = getimagesize($source_filename);
Línea 1138... Línea 1125...
1138
                } else {
1125
                } else {
1139
                    $resized_height = $target_height;
1126
                    $resized_height = $target_height;
1140
                    $resized_width = $source_width * $height_ratio;
1127
                    $resized_width = $source_width * $height_ratio;
1141
                }
1128
                }
Línea 1142... Línea -...
1142
 
-
 
1143
 
-
 
1144
 
1129
 
1145
                $resized_width = round($resized_width);
1130
                $resized_width = round($resized_width);
Línea 1146... Línea 1131...
1146
                $resized_height = round($resized_height);
1131
                $resized_height = round($resized_height);
1147
 
1132
 
Línea -... Línea 1133...
-
 
1133
                $offset_width = round(($target_width - $resized_width) / 2);
-
 
1134
                $offset_height = round(($target_height - $resized_height) / 2);
-
 
1135
 
-
 
1136
                $new_image = $this->_createImageCanvas($target_width, $target_height);
-
 
1137
                if ($new_image === false) {
-
 
1138
                    imagedestroy($img);
Línea 1148... Línea -...
1148
                $offset_width = round(($target_width - $resized_width) / 2);
-
 
1149
                $offset_height = round(($target_height - $resized_height) / 2);
-
 
1150
 
-
 
1151
 
-
 
1152
                $new_image = imageCreateTrueColor($target_width, $target_height);
-
 
1153
                imageAlphaBlending($new_image, False);
1139
                    unlink($source_filename);
-
 
1140
                    return false;
Línea 1154... Línea 1141...
1154
                imageSaveAlpha($new_image, True);
1141
                }
1155
                $transparent = imageColorAllocateAlpha($new_image, 0, 0, 0, 127);
-
 
1156
                imagefill($new_image, 0, 0, $transparent);
-
 
1157
                imageCopyResampled($new_image, $img, $offset_width, $offset_height, 0, 0, $resized_width, $resized_height, $source_width, $source_height);
-
 
1158
 
1142
 
Línea 1159... Línea 1143...
1159
                imagepng($new_image, $target_filename);
1143
                imageCopyResampled($new_image, $img, $offset_width, $offset_height, 0, 0, $resized_width, $resized_height, $source_width, $source_height);
1160
 
1144
                imagedestroy($img);
1161
                @unlink($source_filename);
1145
 
1162
                return true;
1146
                return $this->_savePngAndCleanup($new_image, $target_filename, $source_filename);
-
 
1147
            }
-
 
1148
 
-
 
1149
            unlink($source_filename);
-
 
1150
            return false;
-
 
1151
        } catch (\Throwable $e) {
1163
            }
1152
            error_log($e->getTraceAsString());
-
 
1153
            if (isset($img) && ($img instanceof \GdImage || is_resource($img))) {
1164
 
1154
                imagedestroy($img);
-
 
1155
            }
1165
            @unlink($source_filename);
1156
            if (isset($new_image) && ($new_image instanceof \GdImage || is_resource($new_image))) {
1166
            return false;
1157
                imagedestroy($new_image);
1167
        } catch (\Throwable $e) {
1158
            }
Línea 1168... Línea 1159...
1168
            error_log($e->getTraceAsString());
1159
            if (isset($source_filename) && file_exists($source_filename)) {
Línea 1178... Línea 1169...
1178
     * @param string $target_filename
1169
     * @param string $target_filename
1179
     * @return boolean
1170
     * @return boolean
1180
     */
1171
     */
1181
    public function uploadImageWithOutChangeSize($source_filename, $target_filename)
1172
    public function uploadImageWithOutChangeSize($source_filename, $target_filename)
1182
    {
1173
    {
1183
 
-
 
1184
        try {
1174
        try {
1185
            $data = file_get_contents($source_filename);
1175
            $data = file_get_contents($source_filename);
1186
 
-
 
1187
 
-
 
1188
            $img = imagecreatefromstring($data);
1176
            $img = imagecreatefromstring($data);
Línea 1189... Línea 1177...
1189
 
1177
 
1190
            if ($img) {
1178
            if ($img) {
Línea 1191... Línea 1179...
1191
                list($source_width, $source_height) = getimagesize($source_filename);
1179
                list($source_width, $source_height) = getimagesize($source_filename);
1192
 
1180
 
1193
                $new_image = imageCreateTrueColor($source_width, $source_height);
1181
                $new_image = $this->_createImageCanvas($source_width, $source_height);
1194
                imageAlphaBlending($new_image, False);
1182
                if ($new_image === false) {
1195
                imageSaveAlpha($new_image, True);
1183
                    imagedestroy($img);
-
 
1184
                    unlink($source_filename);
-
 
1185
                    return false;
1196
                $transparent = imageColorAllocateAlpha($new_image, 0, 0, 0, 127);
1186
                }
-
 
1187
                
Línea 1197... Línea -...
1197
                imagefill($new_image, 0, 0, $transparent);
-
 
1198
                imageCopyResampled($new_image, $img, 0, 0, 0, 0, $source_width, $source_height, $source_width, $source_height);
1188
                imageCopyResampled($new_image, $img, 0, 0, 0, 0, $source_width, $source_height, $source_width, $source_height);
1199
 
-
 
1200
 
-
 
1201
                imagepng($new_image, $target_filename);
-
 
1202
 
1189
                imagedestroy($img);
Línea 1203... Línea 1190...
1203
                @unlink($source_filename);
1190
 
1204
                return true;
1191
                return $this->_savePngAndCleanup($new_image, $target_filename, $source_filename);
1205
            }
1192
            }
1206
 
1193
 
-
 
1194
            unlink($source_filename);
-
 
1195
            return false;
-
 
1196
        } catch (\Throwable $e) {
-
 
1197
            error_log($e->getTraceAsString());
-
 
1198
            if (isset($img) && ($img instanceof \GdImage || is_resource($img))) {
1207
            @unlink($source_filename);
1199
                imagedestroy($img);
-
 
1200
            }
1208
            return false;
1201
            if (isset($new_image) && ($new_image instanceof \GdImage || is_resource($new_image))) {
-
 
1202
                imagedestroy($new_image);
1209
        } catch (\Throwable $e) {
1203
            }
1210
            error_log($e->getTraceAsString());
1204
            if (isset($source_filename) && file_exists($source_filename)) {
1211
 
1205
                unlink($source_filename);
Línea 1212... Línea 1206...
1212
            @unlink($source_filename);
1206
            }