EvrenOnur adlı üyeden alıntı: mesajı görüntüle
Hocalarım bir bot ile uğraşıyorum en son olarak resim işlemi yapmam lazım ve bu konuda deneyimli değilim yardımcı olmanız adına birkaç soru soracağım.
Elimde 6 adet resmim var bunları alıp 3 yukarda 3 altta olacak şekilde toplam 900x600 formatında nasıl birleştirebilirim. Diğer resimlerin boyutları farklı fakat kırpma vs hiç problem değil. Bu işlemi nasıl yapabilirim yardımcı olurmusunuz? örnek aşağıdaki gibi
<?php
class imageGrid
{

    private $realWidth;
    private $realHeight;
    private $gridWidth;
    private $gridHeight;
    private $image;

    public function __construct($realWidth, $realHeight, $gridWidth, $gridHeight)
    {
        $this->realWidth = $realWidth;
        $this->realHeight = $realHeight;
        $this->gridWidth = $gridWidth;
        $this->gridHeight = $gridHeight;

        // create destination image
        $this->image = imagecreatetruecolor($realWidth, $realHeight);
        $black = imagecolorallocate($this->image, 0, 0, 0);
        imagecolortransparent($this->image, $black);
    }

    public function __destruct()
    {
        imagedestroy($this->image);
    }

    public function display()
    {
        header("Content-type: image/png");
        imagepng($this->image);
    }

    public function putImage($img, $sizeW, $sizeH, $posX, $posY)
    {
        // Cell width
        $cellWidth = $this->realWidth / $this->gridWidth;
        $cellHeight = $this->realHeight / $this->gridHeight;

        // Conversion of our virtual sizes/positions to real ones
        $realSizeW = ceil($cellWidth * $sizeW);
        $realSizeH = ceil($cellHeight * $sizeH);
        $realPosX = ($cellWidth * $posX);
        $realPosY = ($cellHeight * $posY);

        $img = $this->resizePreservingAspectRatio($img, $realSizeW, $realSizeH);

        // Copying the image
        imagecopyresampled($this->image, $img, $realPosX, $realPosY, 0, 0, $realSizeW, $realSizeH, imagesx($img), imagesy($img));
    }

    public function resizePreservingAspectRatio($img, $targetWidth, $targetHeight)
    {
        $srcWidth = imagesx($img);
        $srcHeight = imagesy($img);

        $srcRatio = $srcWidth / $srcHeight;
        $targetRatio = $targetWidth / $targetHeight;
        if (($srcWidth <= $targetWidth) && ($srcHeight <= $targetHeight))
        {
            $imgTargetWidth = $srcWidth;
            $imgTargetHeight = $srcHeight;
        }
        else if ($targetRatio > $srcRatio)
        {
            $imgTargetWidth = (int) ($targetHeight * $srcRatio);
            $imgTargetHeight = $targetHeight;
        }
        else
        {
            $imgTargetWidth = $targetWidth;
            $imgTargetHeight = (int) ($targetWidth / $srcRatio);
        }

        $targetImg = imagecreatetruecolor($targetWidth, $targetHeight);

        imagecopyresampled(
            $targetImg,
            $img,
            ($targetWidth - $imgTargetWidth) / 2, // centered
            ($targetHeight - $imgTargetHeight) / 2, // centered
            0,
            0,
            $imgTargetWidth,
            $imgTargetHeight,
            $srcWidth,
            $srcHeight
        );

        return $targetImg;
    }

}
function resize_image($file, $w, $h, $crop=TRUE) {
    list($width, $height) = getimagesize($file);
    $r = $width / $height;
    if ($crop) {
        if ($width > $height) {
            $width = ceil($width-($width*abs($r-$w/$h)));
        } else {
            $height = ceil($height-($height*abs($r-$w/$h)));
        }
        $newwidth = $w;
        $newheight = $h;
    } else {
        if ($w/$h > $r) {
            $newwidth = $h*$r;
            $newheight = $h;
        } else {
            $newheight = $w/$r;
            $newwidth = $w;
        }
    }
    $src = imagecreatefromjpeg($file);
    $dst = imagecreatetruecolor($newwidth, $newheight);
    imagecopyresampled($dst, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

    return $dst;
}



$imageGrid = new imageGrid(900, 524, 12, 2);

$blue = resize_image("images/1.jpg",300,262);
$imageGrid->putImage($blue, 4, 1, 0, 0);
imagedestroy($blue);

$green = resize_image("images/2.jpg",300,262);
$imageGrid->putImage($green, 4, 1, 4, 0);
imagedestroy($green);

$red = resize_image("images/3.jpg",300,262);
$imageGrid->putImage($red, 4, 1, 8, 0);
imagedestroy($red);

$yellow = resize_image("images/1.jpg",300,262);
$imageGrid->putImage($yellow, 4, 1, 0, 1);
imagedestroy($yellow);

$purple = resize_image("images/2.jpg",300,262);
$imageGrid->putImage($purple, 4, 1, 4, 1);
imagedestroy($purple);

$cyan = resize_image("images/3.jpg",300,262);
$imageGrid->putImage($cyan, 4, 1, 8, 1);
imagedestroy($cyan);

$imageGrid->display();
Buyrun hocam