Upload images → Arrange until the specified size → Save as a single image

Asked 2 years ago, Updated 2 years ago, 120 views

What should I do if I want to implement the following?
·Image upload
·Arrange
until the specified size (in XY direction) ·Save as a single image

Question
"·After uploading the image, I think I saw an ImageMagic sample online that magnifies the image itself and trims the image itself, but I don't know what to do with ""arranging it until the specified size""
" ·After displaying it side by side in CSS, capture the elements?
·Even if you don't do that, can you do something with ImageMagic?

Other
·The joints are not seamless, just repeat the arrangement
·It doesn't have to be ImageMagic

javascript php image imagemagick

2022-09-30 13:45

1 Answers

It seems to be easy to implement with GD.
I don't know what to do with the overhanging sample below, so I try to overhanging it.
I didn't check if the image was POSTed, so please try to insert it yourself.

<?php

// Image Height to Specify
$maxHeight=(int)$_POST['max_height'];

// Width of image to specify
$maxWidth=(int)$_POST ['max_width'];

// uploaded image
$image=$_FILES['image']['tmp_file'];

// Divided by /
$mimeType=explode('/',$_FILES['image']['type']);

if($mimeType[1]==='jpeg'||$mimeType[1]==='png'||$mimeType[1]==='gif'){

    // GD the uploaded image
    $functionName='imagecreatefrom'.$mimeType[1];
    $gdImage=$functionName($image);

    // image height
    $imageHeight=imagesy($gdImage);

    // image width
    $imageWidth=imagesx($gdImage);

    // GD for copy
    $result=imagecreateruecolor($maxWidth,$maxHeight);

    // Number of vertical copies (floor if not overhanging)
    $copyY=ceil($maxHeight/$imageHeight);

    // Number of horizontal copies (floor if not overhanging)
    $copyX=ceil($maxWidth/$imageWidth);

    // copy away
    for($y=0;$y<$copyY;$y++){
        for($x=0;$x<$copyX;$x++){
            imagecopy($result,$gdImage,$x*$imageWidth,$y*$imageHeight,0,$imageWidth,$imageHeight);
        }
    }

    // output the results of
    $outputFunctionName='image'.$mimeType[1];
    $outputFunctionName($result,'./output.'.$mimeType[1]);

}


2022-09-30 13:45

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.