HEX
Server: Apache/2.4.25 (Debian)
System: Linux server17 4.9.0-19-amd64 #1 SMP Debian 4.9.320-2 (2022-06-30) x86_64
User: web37 (1062)
PHP: 7.4.30
Disabled: show_source, highlight_file, apache_child_terminate, apache_get_modules, apache_note, apache_setenv, virtual, dl, disk_total_space, posix_getpwnam, posix_getpwuid, posix_mkfifo, posix_mknod, posix_setpgid, posix_setsid, posix_setuid, posix_uname, proc_nice, openlog, syslog, pfsockopen
Upload Files
File: /var/www/web37/htdocs/fickanzeiger/components/ImageResizer.php
<?php
/**
 * Arfooo
 * 
 * @package    Arfooo
 * @copyright  Copyright (c) Arfooo Annuaire (fr) and Arfooo Directory (en)
 *             by Guillaume Hocine (c) 2007 - 2010
 *             http://www.arfooo.com/ (fr) and http://www.arfooo.net/ (en)
 * @author     Guillaume Hocine & Adrian Galewski
 * @license    http://creativecommons.org/licenses/by/2.0/fr/ Creative Commons
 */


class ImageResizer
{
    function resize($srcPath, $dstPath, $newWidth, $newHeight, $proporcion = true, $fixedSize = false)
    {
        $srcImage = new Image($srcPath);

        $newTotalWidth = $newWidth;
        $newTotalHeight = $newHeight;

        if ($proporcion) {
            $scale = max($srcImage->getWidth() / $newWidth, $srcImage->getHeight() / $newHeight);

            $newWidth = floor($srcImage->getWidth() / $scale);
            $newHeight = floor($srcImage->getHeight() / $scale);
        }

        $dstImage = new Image();

        if ($fixedSize) {
            $dstImage->createNew($newTotalWidth, $newTotalHeight);
            $whiteIndex = imagecolorallocate($dstImage->im, 255, 255, 255);
            imagefill($dstImage->im, 0, 0, $whiteIndex);
        } else {
            $dstImage->createNew($newWidth, $newHeight);
        }

        $transparentIndex = imagecolortransparent($srcImage->im);

        if ($transparentIndex >= 0) {
            $transparentColor = imagecolorsforindex($srcImage->im, $transparentIndex);
            $transparentIndex = imagecolorallocate($dstImage->im, $transparentColor['red'], $transparentColor['green'], $transparentColor['blue']);
            imagefill($dstImage->im, 0, 0, $transparentIndex);
            imagecolortransparent($dstImage->im, $transparentIndex);
        }

        if ($fixedSize) {
            $horizontalMargin = ($newTotalWidth - $newWidth) / 2;
            $verticalMargin = ($newTotalHeight - $newHeight) / 2;
        } else {
            $horizontalMargin = 0;
            $verticalMargin = 0;
        }

        imagecopyresampled($dstImage->im, $srcImage->im, $horizontalMargin, $verticalMargin, 0, 0, $newWidth, $newHeight, $srcImage->getWidth(), $srcImage->getHeight());

        $dstImage->setPath($dstPath);
        $dstImage->saveToFile();

    }

    function addTag($srcPath, $dstPath)
    {
        $srcImage = new Image($srcPath);

        $tagImagePath = CODE_ROOT_DIR . "uploads/custom/" . Config::get("watermarkImageSrc");

        if (!file_exists($tagImagePath)) {
            return;
        }

        $tagImage = new Image($tagImagePath);

        list ($posV, $posH) = explode(",", Config::get("imageWatermarkPosition"));

        $tagMarginH = 5;
        $tagMarginV = 5;

        if ($posH == "l") {
            $tagPositionX = 0 + $tagMarginH;
        } else {
            $tagPositionX = max($srcImage->getWidth() - $tagImage->getWidth() - $tagMarginH, 0);
        }
        if ($posV == "t") {
            $tagPositionY = 0 + $tagMarginV;
        } else {
            $tagPositionY = max($srcImage->getHeight() - $tagImage->getHeight() - $tagMarginV, 0);
        }
        imagecopyresampled($srcImage->im, $tagImage->im, $tagPositionX, $tagPositionY, 0, 0, $tagImage->getWidth(), $tagImage->getHeight(), $tagImage->getWidth(), $tagImage->getHeight());

        $srcImage->setPath($dstPath);
        $srcImage->saveToFile();
    }
}