Generate crop schemes

@return array
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;
    }
79782
public function getCMSFields()
    {
        $fields = parent::getCMSFields();
        $fields->addFieldsToTab(
            "Root.Main",
            array(
                TextareaField::create(
                    'Title'
                )->setRows(1),
                HTMLEditorField::create(
                    'Content'
                )
            )
        );

        $this->extend('updateCMSFields', $fields);

        return $fields;
    }
1203478
public function toArray()
    {
        $commands = array();

        $maybeAppend = function ($command) use (&$commands) {
            if ($command) $commands []= (string) $command;
        };

        if ($this->metadataOnly) {
            $commands []= 'meta';
        }

        $maybeAppend($this->trim);
        $maybeAppend($this->crop);
        $maybeAppend($this->resize);
        $maybeAppend($this->halign);
        $maybeAppend($this->valign);

        if ($this->smartCrop) {
            $commands []= 'smart';
        }

        if (count($this->filters)) {
            $filters = 'filters:' . implode(':', $this->filters);
            $commands []= $filters;
        }

        return $commands;
    }
681373
public function getCMSFields()
    {
        $fields = parent::getCMSFields();
        $fields->addFieldsToTab(
            'Root.Main',
            array(
                TextField::create(
                    'AdditionalType',
                    _t('SchemaThing.ADDITIONALTYPE', 'Additional Type')
                ),
                TextField::create(
                    'AlternativeName',
                    _t('SchemaThing.ALTERNATIVENAME', 'Alternative Name')
                ),
                TextareaField::create(
                    'Description',
                    _t('SchemaThing.DESCRIPTION', 'Description')
                ),
                TextareaField::create(
                    'DisambiguatingDescription',
                    _t('SchemaThing.DISAMBIGUATINGDESCRIPTION', 'Disambiguating Description')
                ),
                TextField::create(
                    'Name',
                    _t('SchemaThing.NAME', 'Name')
                ),
                TextField::create(
                    'SameAs',
                    _t('SchemaThing.SAMEAS', 'Same as')
                ),
                TextField::create(
                    'Url',
                    _t('SchemaThing.URL', 'URL')
                ),
                UploadField::create(
                    'Image',
                    _t('SchemaThing.IMAGE', 'Image')
                )
            )
        );
        return $fields;
    }
374576
public function generateModels()
    {
        $sourceRoot = $this->source . '/Model';

        $destinationRoot = $this->cwd
            . $this->schema['paths']['model']
            . '/' . ucwords($this->schema['name']);

        if(!is_dir($destinationRoot)) {
            mkdir($destinationRoot, 0777, true);
        }

        foreach($this->schema['model'] as $action) {
            $source = $sourceRoot . '/' . ucwords($action) . '.html';

            $destination = $destinationRoot . '/' . ucwords($action) . '.php';

            if(!file_exists($source)) {
                Index::error(sprintf(
                    self::SKIP,
                    'Model',
                    ucwords($action)),
                false);

                continue;
            }

            $this->copy($source, $destination);
        }
    }
324409
public function getCMSFields()
    {
        // Obtain Field Objects (from parent):
        
        $fields = parent::getCMSFields();
        
        // Create Field Objects:
        
        $fields->fieldByName('Root.Options.TitleOptions')->push(
            CheckboxField::create(
                'UseLevelTitle',
                $this->fieldLabel('UseLevelTitle')
            )
        );
        
        // Answer Field Objects:
        
        return $fields;
    }
1306336
public function getManipulators()
    {
        return [
            new Orientation(),
            new Crop(),
            new Size($this->getMaxImageSize()),
            new Brightness(),
            new Contrast(),
            new Gamma(),
            new Sharpen(),
            new Filter(),
            new Flip(),
            new Blur(),
            new Pixelate(),
            new Watermark($this->getWatermarks(), $this->getWatermarksPathPrefix()),
            new Background(),
            new Border(),
            new Encode(),
        ];
    }
131321
protected function _updateCropTemplateRefs() {
        $iniPaths = ['/configs/content.ini', '/configs/acl.ini'];
        foreach ($iniPaths as $i => $path) {
            $content = file_get_contents(APPLICATION_PATH . $path);
            $content = str_replace('G_Model_CropTemplate', 'Garp_Model_Db_CropTemplate', $content);
            file_put_contents(APPLICATION_PATH . $path, $content);
        }
    }
328315
public function generate(): array
    {
        // create temporay directory
        $tempDir = new Tempdir('sprite');
        $tempDir->addPlugin(new ListFiles);

        // get basic info about video
        $ffprobe  = FFProbe::create()->format($this->getSource());
        $duration = (float)$ffprobe->get('duration');

        // check if sample rate is high enough to reach desired minimum amount of thumbnails
        if ($duration <= $this->getMinThumbs()) {
            // we only have a 1 second resolution, so we can't get lower than 1 obviously
            $this->setRate(1);
        } else {
            if ($duration / $this->getRate() < $this->getMinThumbs()) {
                // sample rate too high, let's adjust rate a little
                $this->setRate((int)floor($duration / $this->getMinThumbs()));
            }
        }

        $this->thumbnailer
            ->setSource($this->getSource())
            ->setWidth($this->getWidth())
            ->setDestination($tempDir->getPath());

        // capture images to tempdir
        for ($i = 0; $i <= $duration; $i += $this->getRate()) {
            $this->thumbnailer->run($i, (int)floor($i / $this->getRate()));
        }

        if (!empty($this->outputImageDirectory)) {
            foreach ($tempDir->listFiles() as $image) {
                copy($tempDir->getPath() . $image['path'], $this->outputImageDirectory . $image['basename']);
            }
        }

        // combine all images to one sprite with quadratic tiling
        $gridSize   = ceil(sqrt(count($tempDir->listFiles())));
        $firstImage = Image::make(sprintf('%s/0001.jpg', $tempDir->getPath()));
        $spriteFile = sprintf('%s/%s.jpg',
            $this->getOutputDirectory(),
            $this->getPrefix()
        );

        $spriteUrl = empty($this->getUrlPrefix())
            ? basename($spriteFile)
            : sprintf('%s/%s', $this->getUrlPrefix(), basename($spriteFile));

        $cmd = sprintf('montage %1$s/*.jpg -tile %2$dx -geometry %3$dx%4$d+0+0 %5$s',
            $tempDir->getPath(),
            $gridSize,
            $firstImage->width(),
            $firstImage->height(),
            $spriteFile
        );

        $proc = new Process($cmd);
        $proc->run();

        if (!$proc->isSuccessful()) {
            throw new \RuntimeException($proc->getErrorOutput());
        }

        // create WebVTT output
        $vttFile = sprintf('%s/%s.vtt',
            $this->getOutputDirectory(),
            $this->getPrefix()
        );

        $vtt      = new WebvttFile();
        $numFiles = count($tempDir->listFiles());

        for ($i = 0; $i < $numFiles; $i++) {
            $start = $i * $this->getRate();
            $end   = ($i + 1) * $this->getRate();
            $x     = ($i % $gridSize) * $firstImage->width();
            $y     = floor($i / $gridSize) * $firstImage->height();

            $vtt->addCue(new WebvttCue(
                    $this->secondsToCue($start),
                    $this->secondsToCue($end),
                    sprintf('%s#xywh=%d,%d,%d,%d',
                        $spriteUrl,
                        $x,
                        $y,
                        $firstImage->width(),
                        $firstImage->height()
                    )
                )
            );
        }

        $vtt->build();
        $vtt->save($vttFile);

        return [
            'vttFile' => $vttFile,
            'sprite'  => $spriteFile,
        ];
    }
1059061
public function getCMSFields()
    {
        // Obtain Field Objects (from parent):
        
        $fields = parent::getCMSFields();
        
        // Create Options Fields:
        
        $fields->addFieldToTab(
            'Root.Options',
            FieldSection::create(
                'NavigationOptions',
                $this->fieldLabel('NavigationOptions'),
                [
                    CheckboxField::create(
                        'HideTopLevel',
                        $this->fieldLabel('HideTopLevel')
                    )
                ]
            )
        );
        
        // Answer Field Objects:
        
        return $fields;
    }
450770
public function getCMSFields()
    {
        // Obtain Field Objects (from parent):
        
        $fields = parent::getCMSFields();
        
        // Create Main Fields:
        
        $fields->addFieldToTab(
            'Root.Main',
            HTMLEditorField::create(
                'Content',
                $this->fieldLabel('Content')
            ),
            'LinkTo'
        );
        
        // Create Options Fields:
        
        $fields->addFieldToTab(
            'Root.Options',
            FieldSection::create(
                'ContentOptions',
                $this->fieldLabel('ContentOptions'),
                [
                    DropdownField::create(
                        'LinkMode',
                        $this->fieldLabel('LinkMode'),
                        $this->getLinkModeOptions()
                    ),
                    TextField::create(
                        'ButtonLabel',
                        $this->fieldLabel('ButtonLabel')
                    )
                ]
            )
        );
        
        // Answer Field Objects:
        
        return $fields;
    }
141687
public function getRootFormat()
    {
        $result = [];
        $roots  = $this->getRoot();
        foreach ($roots as $key => $node) {

            $v = $node->formatNode();

            $result = array_merge($result, $v);
        }
        return $result;
    }
830950
public function getCMSFields()
    {
        $fields = parent::getCMSFields();

        $fields->addFieldToTab(
            'Root.Blocks',
            GridField::create(
                'Blocks',
                'Blocks',
                $this->Blocks(),
                GridFieldConfig_MultiClassRecord::create(
                    $this->Blocks(),
                    singleton('BlockObject_Preset')->SubClassNames
                )
            )
        );
        $this->extend('updateCMSFields', $fields);
        return $fields;
    }
217742
public function getCropDimensions() {
		$x = $this->getCropX();
		$y = $this->getCropY();
		$cropWidth = $this->getCropWidth();
		$cropHeight = $this->getCropHeight();
		$width = $cropWidth;
		$height = $cropHeight;

		// Normalise the width/height with respect to the aspect ratio
		$maxWidth = $this->getMaxWidth();
		$maxHeight = $this->getMaxHeight();

		$aspectRatio = $this->getAspectRatio();


		if($width < 1 || $height < 1) {
			throw new \InvalidArgumentException('Values must be over 1');
		}

		// Fix the aspect ratio if the crop is wrong
		// This must happen first so invalid values can be compensated for
		if($width / $height != $aspectRatio) {
			$height = $width / $aspectRatio;
		}

		if($width > $maxWidth) {
			$scaleDownRatio = $cropWidth / $maxWidth;
			$height = $height / $scaleDownRatio;
			$width = $maxWidth;
		}

		if($height > $maxHeight) {
			$scaleDownRatio = $cropHeight / $maxHeight;
			$width = $width / $scaleDownRatio;
			$height = $maxHeight;
		}

		return array(
			// src_x, src_y
			'x' => $x,
			'y' => $y,
			// dst_w, dst_h
			'width' => ceil($width),
			'height' => ceil($height),
			// src_w, src_h
			'crop_width' => $cropWidth,
			'crop_height' => $cropHeight,
		);
	}
1348305
public function generateResources()
    {

        Artisan::call('module:make-seed', [
            'name' => $this->getName(),
            'module' => $this->getName(),
            '--master' => true,
        ]);

        Artisan::call('module:make-provider', [
            'name' => $this->getName() . 'ServiceProvider',
            'module' => $this->getName(),
            '--master' => true,
        ]);

        Artisan::call('module:make-controller', [
            'controller' => $this->getName() . 'Controller',
            'module' => $this->getName(),
        ]);
    }
991034
protected function getFields()
    {
        return [
          'title' => new Field('Project title', [
            'optionName' => 'title',
            'description' => 'The initial project title',
            'questionLine' => '',
            'default' => 'Untitled Project',
          ]),
          'region' => new OptionsField('Region', [
            'optionName' => 'region',
            'description' => 'The region where the project will be hosted',
            'options' => $this->getAvailableRegions(),
            'optionsCallback' => function () {
                return $this->getAvailableRegions(true);
            },
          ]),
          'plan' => new OptionsField('Plan', [
            'optionName' => 'plan',
            'description' => 'The subscription plan',
            'options' => $this->getAvailablePlans(),
            'default' => in_array('development', $this->getAvailablePlans()) ? 'development' : null,
            'allowOther' => true,
          ]),
          'environments' => new Field('Environments', [
            'optionName' => 'environments',
            'description' => 'The number of environments',
            'default' => 3,
            'validator' => function ($value) {
                return is_numeric($value) && $value > 0 && $value < 50;
            },
          ]),
          'storage' => new Field('Storage', [
            'description' => 'The amount of storage per environment, in GiB',
            'default' => 5,
            'validator' => function ($value) {
                return is_numeric($value) && $value > 0 && $value < 1024;
            },
          ]),
        ];
    }
41261
public function getCropsDisk() {
        if (empty($this->crops_disk)) {
            $this->setCropsDisk($this->makeDisk($this->config['crops_dir']));
        }
        return $this->crops_disk;
    }