dongmeng0317 2017-06-11 18:21
浏览 71

在php中为谷歌自定义街景全景创建图块

i am working in a web application in php where i want to use google custom street view panorama (Google example) with my local images. but i couldnt get any way to create tiles from the uploaded (by user) 360 image to work with the api.

i have tried this following script to create tiles, but the tiles are not correct and quality is too bad,

function tileCreator($fileName){
//Larger images can require more memory and time
ini_set('memory_limit','2048M');
ini_set('max_execution_time','300');
//For testing purposes, I manually entered the input file name and destination folder
$destinationDir = 'tiles/';
if (!file_exists($destinationDir)) {
    mkdir($destinationDir, 0777, true);
}
//create transform driver object
$im = imagecreatefromjpeg($fileName);
$sizeArray = getimagesize($fileName);
//Set the Image dimensions
$imageWidth = $sizeArray[0];
$imageHeight = $sizeArray[1];
//See how many zoom levels are required for the width and height
$widthLog = ceil(log($imageWidth/256,2));
$heightLog = ceil(log($imageHeight/256,2));
//Find the maximum zoom by taking the higher of the width and height zoom levels
if ($heightLog > $widthLog)
{
    $maxZoom = $heightLog;
}
else
{
    $maxZoom = $widthLog;
}
//Go through each zoom level
for ($z =0 ; $z < $maxZoom ; $z++ )
{
    $currSize = 256 * pow(2,$z);
    for ($y = 0 ; $y * $currSize < $imageHeight ; $y++)
    {
    //if the current square on the original doesn't have the required height, we need to find the correct ratio to use or the image could be skewed
        if (($imageHeight - $y*$currSize) < $currSize)
        {
            $heightRatio = ($imageHeight-$y*$currSize)/$currSize;
        }
        else
        {
            $heightRatio = 1;
        }
    //if the current square on the original doesn't have the required width, we need to find the correct ratio to use or the image could be skewed
    for($x = 0 ; $x * $currSize < $imageWidth ; $x++)
        {
            if (($imageWidth-$x*$currSize) < $currSize)
            {
                $widthRatio = ($imageWidth-$x*$currSize)/$currSize;
            }
            else
            {
                $widthRatio = 1;
            }
        //create an image to put this tile in
        $dest = imagecreatetruecolor(256*$widthRatio,256*$heightRatio);
        //take the correct chunk from the original, and rescale it to fit in the tile
        $ret = imagecopyresized($dest, $im, 0, 0, $x*$currSize, $y*$currSize, 256*$widthRatio, 256*$heightRatio, $currSize*$widthRatio, $currSize*$heightRatio);
            //save this image as a jpg, named according to its location and zoom
            $folder = $destinationDir . ($maxZoom-$z) . '/' . $x . '/';
            if (!file_exists($folder)) {
                mkdir($folder, 0777, true);
            }
            imagejpeg($dest, $folder . $y . '.jpg', 75);
            imagedestroy($dest);
        }
    }
}

}

please help if anyone has any php script or library which can create tiles for custom street view panorama.

Thanks

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于smbclient 库的使用
    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画