Generate a map!

@return \Intervention\Image\Image
337186
public function run()
    {
        $header = $this->rec->header();
        $mapData = $header->mapData;
        $mapSize = count($mapData);
        $image = $this->imageManager->canvas($mapSize, $mapSize);
        $p = $this->rec->getResourcePack();

        foreach ($mapData as $y => $row) {
            foreach ($row as $x => $tile) {
                $variation = 1;
                if ($this->showElevation) {
                    if (isset($mapData[$y + 1][$x + 1])) {
                        $bottomRight = $mapData[$y + 1][$x + 1];
                        if ($bottomRight->elevation < $tile->elevation) {
                            $variation = 0;
                        } else if ($bottomRight->elevation > $tile->elevation) {
                            $variation = 2;
                        }
                    }
                }
                $color = $p->getTerrainColor($tile->terrain, $variation);
                if (!is_null($color)) {
                    $this->fastPixel($image, $x, $y, $color);
                } else {
                    throw new \Exception(sprintf('Unknown terrain ID \'%d\'', $tile->terrain));
                }
            }
        }

        $gaiaObjects = $this->sortObjects($header->playerInfo->gaiaObjects);

        foreach ($gaiaObjects as $obj) {
            $color = $p->getUnitColor($obj->id);
            list ($x, $y) = $obj->position;
            $image->rectangle($x - 1, $y - 1, $x + 1, $y + 1, function ($shape) use ($color) {
                $shape->background($color);
            });
        }

        if ($this->showPlayerUnits) {
            foreach ($header->playerInfo->playerObjects as $object) {
                if ($object->owner->index < 0) {
                    continue;
                }
                $color = $object->owner->color();
                list ($x, $y) = $object->position;
                $image->rectangle($x - 1, $y - 1, $x + 1, $y + 1, function ($shape) use ($color) {
                    $shape->background($color);
                });
            }
        }

        if ($this->showPositions) {
            foreach ($header->players as $player) {
                if ($player->isCooping || $player->isSpectator()) {
                    continue;
                }

                $color = $player->color();
                list ($x, $y) = $player->position();
                $image->circle(18, $x, $y, function ($shape) use ($color) {
                    $shape->border(1, $color);
                });
                $image->circle(8, $x, $y, function ($shape) use ($color) {
                    $shape->background($color);
                });
            }
        }

        return $image->rotate(45, [0, 0, 0, 0]);
    }
798470
public function getWrappedImage()
    {
        if(!$this->zendImage)
        {
            $this->zendImage = $this->createImage($this->path);
            $this->path = null;
        }

        return $this->zendImage;
    }
671377
public static function getMapping()
    {
        $instance = new static();

        $params = $instance->getBasicEsParams();

        return $instance->getElasticSearchClient()->indices()->getMapping($params);
    }
675132
public function createMap() {
        if(is_null($this->schema)) {
            throw SystemException::forNoSchema();
        }

        // translate data first to sql
        $data = $this->schema->toSql();

        // then translate it to elastic mapping
        $mapping = $this->schema->toElastic($data);
        // get schema path
        $path = cradle()->package('global')->path('schema') . '/elastic';
        // if elastic dir doesn't exists
        // create elastic folder
        if(!is_dir($path)) {
            mkdir($path, 0777);
        }

        // if elastic schema dir doesn't exist
        // create elastic schema dir
        mkdir ($path . '/' . ucwords($data['name']));

        // save mapping
        file_put_contents(
            $path . '/' . ucwords($data['name']) . '/elastic.php',
            '<?php //-->' . "\n return " .
            var_export($mapping, true) . ';'
        );
    }
1134863
protected function buildPropertyMap()
    {
        $map = [];
        $properties = (new ReflectionObject($this))->getProperties(ReflectionProperty::IS_PUBLIC);

        foreach ($properties as $property) {
            $map[$property->getName()] = $property;
        }

        return $map;
    }
1027289
public function getOverrideMap()
    {
        gplcart_static_clear();

        $map = array();

        foreach ($this->module->getEnabled() as $module) {

            $directory = GC_DIR_MODULE . "/{$module['id']}/override/classes";

            if (!is_readable($directory)) {
                continue;
            }

            foreach ($this->scanOverrideFiles($directory) as $file) {
                $original = str_replace('/', '\\', str_replace($directory . '/', '', preg_replace('/Override$/', '', $file)));
                $override = str_replace('/', '\\', str_replace(GC_DIR_SYSTEM . '/', '', $file));
                $map["gplcart\\$original"][$module['id']] = "gplcart\\$override";
            }
        }

        return $map;
    }
1137361
public function generate()
	{
		$arrSet = array();
		$arrValues = array();
		$blnHasOrder = ($this->orderField != '' && \is_array($this->{$this->orderField}));

		if (!empty($this->varValue)) // Can be an array
		{
			$objFiles = \FilesModel::findMultipleByUuids((array) $this->varValue);
			$allowedDownload = \StringUtil::trimsplit(',', strtolower(\Config::get('allowedDownload')));

			if ($objFiles !== null)
			{
				while ($objFiles->next())
				{
					// File system and database seem not in sync
					if (!file_exists(TL_ROOT . '/' . $objFiles->path))
					{
						continue;
					}

					$arrSet[$objFiles->id] = $objFiles->uuid;

					// Show files and folders
					if (!$this->isGallery && !$this->isDownloads)
					{
						if ($objFiles->type == 'folder')
						{
							$arrValues[$objFiles->uuid] = \Image::getHtml('folderC.svg') . ' ' . $objFiles->path;
						}
						else
						{
							$objFile = new \File($objFiles->path);
							$strInfo = $objFiles->path . ' <span class="tl_gray">(' . $this->getReadableSize($objFile->size) . ($objFile->isImage ? ', ' . $objFile->width . 'x' . $objFile->height . ' px' : '') . ')</span>';

							if ($objFile->isImage)
							{
								$arrValues[$objFiles->uuid] = $this->getPreviewImage($objFile, $strInfo);
							}
							else
							{
								$arrValues[$objFiles->uuid] = \Image::getHtml($objFile->icon) . ' ' . $strInfo;
							}
						}
					}

					// Show a sortable list of files only
					else
					{
						if ($objFiles->type == 'folder')
						{
							$objSubfiles = \FilesModel::findByPid($objFiles->uuid, array('order' => 'name'));

							if ($objSubfiles === null)
							{
								continue;
							}

							while ($objSubfiles->next())
							{
								// Skip subfolders
								if ($objSubfiles->type == 'folder')
								{
									continue;
								}

								$objFile = new \File($objSubfiles->path);
								$strInfo = '<span class="dirname">' . \dirname($objSubfiles->path) . '/</span>' . $objFile->basename . ' <span class="tl_gray">(' . $this->getReadableSize($objFile->size) . ($objFile->isImage ? ', ' . $objFile->width . 'x' . $objFile->height . ' px' : '') . ')</span>';

								if ($this->isGallery)
								{
									// Only show images
									if ($objFile->isImage)
									{
										$arrValues[$objSubfiles->uuid] = $this->getPreviewImage($objFile, $strInfo);
									}
								}
								else
								{
									// Only show allowed download types
									if (\in_array($objFile->extension, $allowedDownload) && !preg_match('/^meta(_[a-z]{2})?\.txt$/', $objFile->basename))
									{
										$arrValues[$objSubfiles->uuid] = \Image::getHtml($objFile->icon) . ' ' . $strInfo;
									}
								}
							}
						}
						else
						{
							$objFile = new \File($objFiles->path);
							$strInfo = '<span class="dirname">' . \dirname($objFiles->path) . '/</span>' . $objFile->basename . ' <span class="tl_gray">(' . $this->getReadableSize($objFile->size) . ($objFile->isImage ? ', ' . $objFile->width . 'x' . $objFile->height . ' px' : '') . ')</span>';

							if ($this->isGallery)
							{
								// Only show images
								if ($objFile->isImage)
								{
									$arrValues[$objFiles->uuid] = $this->getPreviewImage($objFile, $strInfo, 'gimage removable');
								}
							}
							else
							{
								// Only show allowed download types
								if (\in_array($objFile->extension, $allowedDownload) && !preg_match('/^meta(_[a-z]{2})?\.txt$/', $objFile->basename))
								{
									$arrValues[$objFiles->uuid] = \Image::getHtml($objFile->icon) . ' ' . $strInfo;
								}
							}
						}
					}
				}
			}

			// Apply a custom sort order
			if ($blnHasOrder)
			{
				$arrNew = array();

				foreach ((array) $this->{$this->orderField} as $i)
				{
					if (isset($arrValues[$i]))
					{
						$arrNew[$i] = $arrValues[$i];
						unset($arrValues[$i]);
					}
				}

				if (!empty($arrValues))
				{
					foreach ($arrValues as $k=>$v)
					{
						$arrNew[$k] = $v;
					}
				}

				$arrValues = $arrNew;
				unset($arrNew);
			}
		}

		// Convert the binary UUIDs
		$strSet = implode(',', array_map('StringUtil::binToUuid', $arrSet));
		$strOrder = $blnHasOrder ? implode(',', array_map('StringUtil::binToUuid', $this->{$this->orderField})) : '';

		$return = '<input type="hidden" name="'.$this->strName.'" id="ctrl_'.$this->strId.'" value="'.$strSet.'">' . ($blnHasOrder ? '
  <input type="hidden" name="'.$this->strOrderName.'" id="ctrl_'.$this->strOrderId.'" value="'.$strOrder.'">' : '') . '
  <div class="selector_container">' . (($blnHasOrder && \count($arrValues) > 1) ? '
    <p class="sort_hint">' . $GLOBALS['TL_LANG']['MSC']['dragItemsHint'] . '</p>' : '') . '
    <ul id="sort_'.$this->strId.'" class="'.trim(($blnHasOrder ? 'sortable ' : '').($this->isGallery ? 'sgallery' : '')).'">';

		foreach ($arrValues as $k=>$v)
		{
			$return .= '<li data-id="'.\StringUtil::binToUuid($k).'">'.$v.'</li>';
		}

		$return .= '</ul>';

		if (!\System::getContainer()->get('contao.picker.builder')->supportsContext('file'))
		{
			$return .= '
	<p><button class="tl_submit" disabled>'.$GLOBALS['TL_LANG']['MSC']['changeSelection'].'</button></p>';
		}
		else
		{
			$extras = array('fieldType'=>$this->fieldType);

			if ($this->files)
			{
				$extras['files'] = (bool) $this->files;
			}

			if ($this->filesOnly)
			{
				$extras['filesOnly'] = (bool) $this->filesOnly;
			}

			if ($this->path)
			{
				$extras['path'] = (string) $this->path;
			}

			if ($this->extensions)
			{
				$extras['extensions'] = (string) $this->extensions;
			}

			$return .= '
    <p><a href="' . ampersand(\System::getContainer()->get('contao.picker.builder')->getUrl('file', $extras)) . '" class="tl_submit" id="ft_' . $this->strName . '">'.$GLOBALS['TL_LANG']['MSC']['changeSelection'].'</a></p>
    <script>
      $("ft_' . $this->strName . '").addEvent("click", function(e) {
        e.preventDefault();
        Backend.openModalSelector({
          "id": "tl_listing",
          "title": "' . \StringUtil::specialchars(str_replace("'", "\\'", $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['label'][0])) . '",
          "url": this.href + document.getElementById("ctrl_'.$this->strId.'").value,
          "callback": function(table, value) {
            new Request.Contao({
              evalScripts: false,
              onSuccess: function(txt, json) {
                $("ctrl_' . $this->strId . '").getParent("div").set("html", json.content);
                json.javascript && Browser.exec(json.javascript);
              }
            }).post({"action":"reloadFiletree", "name":"' . $this->strId . '", "value":value.join("\t"), "REQUEST_TOKEN":"' . REQUEST_TOKEN . '"});
          }
        });
      });
    </script>' . ($blnHasOrder ? '
    <script>Backend.makeMultiSrcSortable("sort_'.$this->strId.'", "ctrl_'.$this->strOrderId.'", "ctrl_'.$this->strId.'")</script>' : '');
		}

		$return = '<div>' . $return . '</div></div>';

		return $return;
	}
353684
public function generateCrops()
    {
        $w = imagesx($this->oImg);
        $h = imagesy($this->oImg);
        $results = [];
        $minDimension = min($w, $h);
        $cropWidth = empty ($this->options ['cropWidth']) ? $minDimension : $this->options ['cropWidth'];
        $cropHeight = empty ($this->options ['cropHeight']) ? $minDimension : $this->options ['cropHeight'];
        for ($scale = $this->options ['maxScale']; $scale >= $this->options ['minScale']; $scale -= $this->options ['scaleStep'])
        {
            for ($y = 0; $y + $cropHeight * $scale <= $h; $y += $this->options ['step'])
            {
                for ($x = 0; $x + $cropWidth * $scale <= $w; $x += $this->options ['step'])
                {
                    $results [] = [
                        'x' => $x,
                        'y' => $y,
                        'width' => $cropWidth * $scale,
                        'height' => $cropHeight * $scale
                    ];
                }
            }
        }

        return $results;
    }
511954
public function MicroImage()
    {
        $pixel = $this->config()->pixelate;
        $blur = $this->config()->blur;
        $quality = $this->config()->quality;
        $scale = $this->config()->scale;
        
        $variant = $this->owner->variantName(__FUNCTION__, $pixel, $blur, $quality, $scale);
        return $this->owner->manipulateImage(
            $variant, 
            function (Image_Backend $backend) use ($pixel, $blur, $quality, $scale) {
                $clone = clone $backend;
                $resource = clone $backend->getImageResource();
                $resource->pixelate($pixel)->blur($blur)->encode('jpg', $quality);
                if ($scale != 100) {
                    $width = $backend->getWidth() * ($scale/100);
                    $height = $backend->getHeight() * ($scale/100);
                    $resource->resize($width, $height);
                }
                $clone->setImageResource($resource);
                return $clone;
            }
        );
    }
1068265
public function getSitemapImagesAttribute()
    {
        return $this->images->map(function ($image) {
            return [
                'url' => $image->url,
                'title' => $image->title,
            ];
        })->all();
    }
468938
private function _generateMappings()
    {
        if (!isset($this->_mappings) && $this->_map->mappings) {
            //up to date, nothing to do
            return;
        }
        $this->_mappingsChanged = false;
        if (!count($this->_mappings)) {
            return '';
        }

        foreach ($this->_mappings as $m) {
            if ($m['originalSource'] && !in_array($m['originalSource'], $this->_map->sources)) {
                $this->_map->sources[] = $m['originalSource'];
            }
        }

        $this->_map->names = array();
        foreach ($this->_mappings as $m) {
            if ($m['originalName'] && !in_array($m['originalName'], $this->_map->names)) {
                $this->_map->names[] = $m['originalName'];
            }
        }

        // group mappings by generated line number.
        $groupedMap = $groupedMapEncoded = array();
        foreach ($this->_mappings as $m) {
            $groupedMap[$m['generatedLine']][] = $m;
        }
        ksort($groupedMap);

        $lastGeneratedLine = $lastOriginalSourceIndex = $lastOriginalNameIndex = $lastOriginalLine = $lastOriginalColumn = 0;

        foreach ($groupedMap as $lineNumber => $lineMap) {
            while (++$lastGeneratedLine < $lineNumber) {
                $groupedMapEncoded[] = ';';
            }

            $lineMapEncoded = array();
            $lastGeneratedColumn = 0;

            foreach ($lineMap as $m) {
                $mapEncoded = Kwf_SourceMaps_Base64VLQ::encode($m['generatedColumn'] - $lastGeneratedColumn);
                $lastGeneratedColumn = $m['generatedColumn'];

                // find the index
                if ($m['originalSource']) {
                    $index = array_search($m['originalSource'], $this->_map->sources);
                    $mapEncoded .= Kwf_SourceMaps_Base64VLQ::encode($index - $lastOriginalSourceIndex);
                    $lastOriginalSourceIndex = $index;

                    // lines are stored 0-based in SourceMap spec version 3
                    $mapEncoded .= Kwf_SourceMaps_Base64VLQ::encode($m['originalLine'] - 1 - $lastOriginalLine);
                    $lastOriginalLine = $m['originalLine'] - 1;

                    $mapEncoded .= Kwf_SourceMaps_Base64VLQ::encode($m['originalColumn'] - $lastOriginalColumn);
                    $lastOriginalColumn = $m['originalColumn'];

                    if ($m['originalName']) {
                        $index = array_search($m['originalName'], $this->_map->names);
                        $mapEncoded .= Kwf_SourceMaps_Base64VLQ::encode($index - $lastOriginalNameIndex);
                        $lastOriginalNameIndex = $index;
                    }
                }

                $lineMapEncoded[] = $mapEncoded;
            }

            $groupedMapEncoded[] = implode(',', $lineMapEncoded).';';
        }

        $this->_map->mappings = rtrim(implode($groupedMapEncoded), ';');
    }
201562
public function PrimaryImage()
    {
        // If we have associated an image, return it
        $image = $this->owner->Image();

        if ($image->exists()) {
            return $image;
        }

        // Next try and get a child product image
        $product = $this->owner->AllProducts()->first();

        if (!empty($product)) {
            return $product->PrimaryImage();
        }

        // Finally generate our no product image
        return Helper::generate_no_image();
    }
884575
public function getRoadMap() {
        $road_map = new RoadMap();
        $road_map->append(new LessRoad("LESSCSS", $this->generateCacheDir($this->getProjectRootDir())));
        $road_map->append(new SourceRoad("ROOT", $this->generateCacheDir($this->getProjectRootDir())));
        $road_map->append(new BuildRoad("BuildCache", $this->getProjectRootDir()));
        return $road_map;
    }
1349593
public function getMapToken ()
	{
		/** @var Settings $settings */
		$settings = SimpleMap::getInstance()->getSettings();

		return GeoService::getToken(
			$settings->mapToken,
			$settings->mapTiles
		);
	}
464991
private function createMapping()
    {
        $columns = $this->pdoStatement->columnCount();
        if ($columns > 0) {
            $this->mapping = [];
            for ($i = 0; $i < $columns; $i++) {
                $meta = $this->pdoStatement->getColumnMeta($i);
                $this->mapping[$i] = [$meta['table'], $meta['name']];
            }
        }
    }
878086
public function getInterventionImage()
    {
        if (! isset($this->interventionImage)) {
            $this->interventionImage = $this->makeInterventionImage();
        }

        return $this->interventionImage;
    }
166612
protected function image()
    {
        $locator = Grav::instance()['locator'];

        $file = $this->get('filepath');

        // Use existing cache folder or if it doesn't exist, create it.
        $cacheDir = $locator->findResource('cache://images', true) ?: $locator->findResource('cache://images', true, true);

        // Make sure we free previous image.
        unset($this->image);

        $this->image = ImageFile::open($file)
            ->setCacheDir($cacheDir)
            ->setActualCacheDir($cacheDir)
            ->setPrettyName($this->getImagePrettyName());

        return $this;
    }