【问题标题】:Create big image from lot of small [closed]从很多小图像中创建大图像[关闭]
【发布时间】:2016-04-26 03:47:08
【问题描述】:

我有一个网站,其中前端存在许多不同的图像。每个 ~200 x ~50kb。现在所有这些图像都是根据不同的请求下载的。 (约 200 个请求)我的目标是创建一个大图像并仅使用一个请求下载它,我还想在我的 MySQL 数据库中存储有关图像位置的坐标,因为我将在画布的前端使用它。另外我想在插入大的图像之前重新调整图像的大小,因为 50kb 太大了。新图像上传到特定目录后,它也会自动执行。 所有图像都在一个目录中。我在后端使用 laravel PHP 框架。

【问题讨论】:

标签: php image laravel image-processing


【解决方案1】:

作为起点,您可以使用此代码扫描目录并将找到的每个图像添加到新图像中。它很粗糙,需要调整,但或多或​​少是你所追求的。

<?php
    $dir=realpath( 'c:/wwwroot/images/tmp/' );/* change to suit your environment */
    $col=glob( $dir . '*.*' );/* get all files ( presuming images ) */

    $length=count( $col );/* you could use this to generate new image dimensions dynamically */
    $sizes=array();

    foreach( $col as $file ){
        list( $width, $height, $type, $attr ) = getimagesize( $file );
        $sizes[ realpath( $file ) ]=array( 'w'=>$width, 'h'=>$height, 't'=>$type );
    }

    /* create the new image */
    $img=imagecreatetruecolor(600,600);
    imagecolorallocate( $img, 0,0,0 );
    $x = $y = 0;

    /* add each image to new image */
    foreach( $sizes as $imgpath => $data ){

        $x+=$data['w'];
        $y+=$data['h'];

        $tgt=imagecreatefromjpeg( $imgpath );
        imagecopymerge( $img, $tgt, $x, $y, 0, 0, $data['w'], $data['h'], 100 );
        imagedestroy( $tgt );
    }

    header('Content-Type: image/jpeg');
    imagejpeg( $img );
    imagedestroy($img);
?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-03
    • 2011-05-08
    • 1970-01-01
    • 2011-10-04
    • 1970-01-01
    • 1970-01-01
    • 2013-06-14
    • 1970-01-01
    相关资源
    最近更新 更多