Get copy from external file url for make thumb
@param string $url
@param float $width
@param float $height
432534
public static function fromUrl($url, $width, $height = 0)
    {

        $extension = pathinfo(strtok($url, '?'), PATHINFO_EXTENSION);

        $filename = sprintf('%s/thumb_%s.%s', sys_get_temp_dir(), md5($url), $extension);

        if (! file_exists($filename) && ! @copy($url, $filename, static::getStreamContextOptions())) {

            return static::$config['fallback'];
        }

        $urlizer = new Urlizer();

        static::configureUrlizer($urlizer);
        
        $thumb = new static($filename, $width, $height);

        $basename = $thumb->generateBasename();

        $filename = $urlizer->buildThumbFilename($basename);

        $thumb->getCache($filename);

        return $urlizer->buildThumbUrl($basename);
    }
1114067
public static function resizeImg($image, $width, $height = 0)
    {
        $newImg = self::getImg($image, $width, $height, false, ManipulatorInterface::THUMBNAIL_OUTBOUND);

        if(self::copyImg($newImg, $image)){
            File::delFile($newImg);
        }
    }
220790
public function forceSize($width, $height, $saveAsNewFile = false)
    {
        $width = $width <= 0 ? round($this->getRatio() * $height) : $width;
        $height = $height <= 0 ? round($width / $this->getRatio()) : $height;


        return $this->modifyImageHelper(
            function (Imagick $imagick) use ($width, $height) {
                $imagick->resizeimage($width, $height, Imagick::FILTER_CATROM, 1);
            },
            function () use ($width, $height) {
                return $this->newForceImageSizeBasename($width, $height);
            },
            function (ImageFile $file) use ($width, $height) {
                $file->forceSize($width, $height);
            },
            $saveAsNewFile);

    }
1028536
public function createThumb($imageObj, $width = null, $height = null, array $options = [])
    {
        $extension = File::extension($imageObj->url);
        $basePath = base_path('/');

        if(!is_numeric($width)) {
            throw new \Exception("Width must be a number");
        }

        if ($this->hasImageExtension($extension)) {

            //thumb can only be created if original source exist
            if(file_exists($basePath.$imageObj->url) && File::size($basePath.$imageObj->url)) {

                $thumbDir = base_path($imageObj->fileDirectory . "/" . $width.($height ? 'x'.$height : ""));

                if (!File::exists($thumbDir)) {
                    if (!File::makeDirectory($thumbDir, 0700, true)) {
                        throw new \Exception("Could not create thumb directory '".$thumbDir."'. Please check permissions.");
                    }
                }

                //check if paths are writable
                if (!File::isWritable($thumbDir)) {
                    throw new \Exception("Thumb could not be created because the directory '".$thumbDir."' is not writable!. Please check permissions.");
                }

                //create thumb
                $img = Image::make(base_path($imageObj->url));

                // crop with and height
                if($width && $height) {
                    if (isset($options['resizeCanvas']) && $options['resizeCanvas'] === true) {
                        $img->resize(
                            $width, $height, function ($constraint) {
                                $constraint->aspectRatio();
                            }
                        )->resizeCanvas($width, $height);
                    } else {
                        $img->fit($width, $height);
                    }
                }elseif($width) { // resize only the width of the image
                    $img->resize(
                        $width, null, function ($constraint) {
                            $constraint->aspectRatio();
                        }
                    );
                }
                elseif($height) { // resize only the height of the image
                    $img->resize(
                        null, $height, function ($constraint) {
                            $constraint->aspectRatio();
                        }
                    );
                }

                if ($img->save($thumbDir . '/' . $imageObj->filename, config('image-optimizer.default_quality'))) {
                    // optimize image
                    $this->optimize($thumbDir . '/' . $imageObj->filename);
                    return true;
                }
            }
        }
        return false;
    }
1209930
public function resize($url, $width = 100, $height = null, $crop = false, $quality = 90)
    {
        if ($url) {
            // URL info
            $info = pathinfo($url);
     
            // The size
            if (! $height) {
                $height = $width;
            }
     
            // Quality
            $quality = Config::get('redminportal::image.quality', $quality);
     
            // Directories and file names
            $fileName       = $info['basename'];
            $sourceDirPath  = public_path() . '/' . $info['dirname'];
            $sourceFilePath = $sourceDirPath . '/' . $fileName;
            $targetDirName  = $width . 'x' . $height . ($crop ? '_crop' : '');
            $targetDirPath  = $sourceDirPath . '/' . $targetDirName . '/';
            $targetFilePath = $targetDirPath . $fileName;
            $targetUrl      = asset($info['dirname'] . '/' . $targetDirName . '/' . $fileName);
     
            // Create directory if missing
            try {
                // Create dir if missing
                if (! Filesystem::isDirectory($targetDirPath) and $targetDirPath) {
                    @Filesystem::makeDirectory($targetDirPath);
                }
     
                // Set the size
                $size = new Box($width, $height);
     
                // Now the mode
                $mode = $crop ? ImageInterface::THUMBNAIL_OUTBOUND : ImageInterface::THUMBNAIL_INSET;
     
                if (! Filesystem::exists($targetFilePath) or
                    (Filesystem::lastModified($targetFilePath) < Filesystem::lastModified($sourceFilePath))) {
                    $this->imagine->open($sourceFilePath)
                        ->thumbnail($size, $mode)
                        ->save($targetFilePath, array('quality' => $quality));
                }
            } catch (\Exception $e) {
                Log::error('[IMAGE SERVICE] Failed to resize image "' . $url . '" [' . $e->getMessage() . ']');
            }
     
            return $targetUrl;
        }
    }
508613
public function resize_fill( $width, $height ) 
	{
		$original_aspect = $this->width / $this->height;
		$thumb_aspect = $width / $height;

		if ( $original_aspect >= $thumb_aspect )
		{
		   $new_height = $height;
		   $new_width = $this->width / ($this->height / $height);
		}
		else
		{
		   $new_width = $width;
		   $new_height = $this->height / ($this->width / $width);
		}

		$x = 0 - ( $new_width - $width ) / 2;
		$y = 0 - ( $new_height - $height ) / 2;

		$result = imagecreatetruecolor( $width, $height );
		imagecopyresampled( $result, $this->image_context, $x, $y, 0, 0, $new_width, $new_height, $this->width, $this->height );

		// overwrite the image context 
		$this->image_context = $result;

		// update properties
		$this->reload_context_info();

		// return self
		return $this;
	}
165344
public static function getInstanceByCreate($width, $height)
    {
        $instance = new self();

        // set image dimensions
        $instance->width = (int)$width;
        $instance->height = (int)$height;

        $instance->createImage();

        return $instance;
    }
378269
public function thumbnailAction($storageId, $height, $width)
    {
        $fileManager = $this->get('beaast.core.manager.file');

        /**
         * @var File $file
         */
        $file = $fileManager->findOneBy(['storageId' => $storageId]);

        if (!$file || !in_array($file->getExtension(), ['jpg', 'png', 'gif'], true)) {
            throw $this->createNotFoundException();
        }

        $filePath = $fileManager->getFilePath($file);

        $cacheFileName = 'thumbnail_'.$height.'_'.$width.'_'.$storageId.'.'.$file->getExtension();

        $cacheFilePath = $this->getParameter('kernel.root_dir').'/../var/storage/cache/'.$cacheFileName;
        if (!file_exists($cacheFilePath) && file_exists($filePath)) {
            $imagick = new \Imagick($filePath);
            $imagick->thumbnailImage($width, $height, true);
            file_put_contents($cacheFilePath, $imagick->getImageBlob());
        }

        return $this->cacheAction($cacheFileName);
    }
18350
public function thumb($width, $height)
    {
        $this->resize($width, $height)
             ->crop($width, $height);

        return $this;
    }
507478
public function do_resize($width, $height)
    {
        if (version_compare(PHP_VERSION, '5.5.0') < 0) {
            $image = imagecreatetruecolor($width, $height);
            imagealphablending($image, false);
            imagesavealpha($image, true);

            imagecopyresampled($image, $this->_image, 0, 0, 0, 0, $width, $height, $this->_width, $this->_height);
        } else {
            $image = imagescale($this->_image, $width, $height);
        }

        imagedestroy($this->_image);
        $this->_image = $image;
        $this->_width = imagesx($image);
        $this->_height = imagesy($image);

        return $this;
    }
814953
protected function extent($width, $height, $flag = '')
    {
        extract(
            $this->getCropCoordinates(
                $this->resource->getImageWidth(),
                $this->resource->getImageHeight(),
                $width,
                $height,
                $this->resource->getGravity()
            )
        );

        $this->resource->extentImage($width, $height, $x, $y);
        return $this;
    }
1036102
public function resize($width, $height)
    {
        $this->mode = 'resize';
        $this->targetSize = [$width, $height];
        $this->arguments = [];

        return $this->process();
    }
221549
protected function resizeExact($file, $width, $height)
	{
		return $this->imagine
			->open($file->getRealPath())
			->resize(new Box($width, $height));
	}
442982
public function ThumbnailURL($width, $height)
    {
        $object = $this->getObjectLatestVersion();
        if ($object instanceof Thumbnail) {
            return $object->ThumbnailURL($width, $height);
        }
        return null;
    }
859911
public static function getTimThumb($src, $width, $height, $zoom, $crop='c') 
	{
		if(Yii::app()->params['timthumb_url_replace'] == 1)
			$src = str_replace(Yii::app()->request->baseUrl, Yii::app()->params['timthumb_url_replace_website'], $src);
		
		$image = self::getProtocol().'://'.Yii::app()->request->serverName.Yii::app()->request->baseUrl.'/timthumb.php?src='.$src.'&h='.$height.'&w='.$width.'&zc='.$zoom.'&a='.$crop;
        return $image;
    }
1108664
public function image($width = null, $height = null, array $options = [])
    {
        $url = $this->getImageUrlOrDefault();

        if (pathinfo($url, PATHINFO_EXTENSION) === 'svg') {
            return $url;
        }

        return url(Croppa::url($url, $width, $height, $options));
    }
1158774
public function embed($urls, $name, $width, $height, $options) {
        global $CFG;
        require_once($CFG->libdir . '/filelib.php');

        $sources = array();
        $mediamanager = core_media_manager::instance();
        $datasetup = [];

        $text = null;
        $isaudio = null;
        $hastracks = false;
        $hasposter = false;
        if (array_key_exists(core_media_manager::OPTION_ORIGINAL_TEXT, $options) &&
                preg_match('/^<(video|audio)\b/i', $options[core_media_manager::OPTION_ORIGINAL_TEXT], $matches)) {
            // Original text already had media tag - get some data from it.
            $text = $options[core_media_manager::OPTION_ORIGINAL_TEXT];
            $isaudio = strtolower($matches[1]) === 'audio';
            $hastracks = preg_match('/<track\b/i', $text);
            $hasposter = self::get_attribute($text, 'poster') !== null;
        }

        // Currently Flash in VideoJS does not support responsive layout. If Flash is enabled try to guess
        // if HTML5 player will be engaged for the user and then set it to responsive.
        $responsive = (get_config('media_videojs', 'useflash') && !$this->youtube) ? null : true;
        $flashtech = false;

        // Build list of source tags.
        foreach ($urls as $url) {
            $extension = $mediamanager->get_extension($url);
            $mimetype = $mediamanager->get_mimetype($url);
            if ($mimetype === 'video/quicktime' && (core_useragent::is_chrome() || core_useragent::is_edge())) {
                // Fix for VideoJS/Chrome bug https://github.com/videojs/video.js/issues/423 .
                $mimetype = 'video/mp4';
            }
            // If this is RTMP stream, adjust mimetype to those VideoJS suggests to use (either flash or mp4).
            if ($url->get_scheme() === 'rtmp') {
                if ($mimetype === 'video/x-flv') {
                    $mimetype = 'rtmp/flv';
                } else {
                    $mimetype = 'rtmp/mp4';
                }
            }
            $source = html_writer::empty_tag('source', array('src' => $url, 'type' => $mimetype));
            $sources[] = $source;
            if ($isaudio === null) {
                $isaudio = in_array('.' . $extension, file_get_typegroup('extension', 'audio'));
            }
            if ($responsive === null) {
                $responsive = core_useragent::supports_html5($extension);
            }
            if (($url->get_scheme() === 'rtmp' || !core_useragent::supports_html5($extension))
                    && get_config('media_videojs', 'useflash')) {
                $flashtech = true;
            }
        }
        $sources = implode("\n", $sources);

        // Find the title, prevent double escaping.
        $title = $this->get_name($name, $urls);
        $title = preg_replace(['/&amp;/', '/&gt;/', '/&lt;/'], ['&', '>', '<'], $title);

        if ($this->youtube) {
            $datasetup[] = '"techOrder": ["youtube"]';
            $datasetup[] = '"sources": [{"type": "video/youtube", "src":"' . $urls[0] . '"}]';
            $sources = ''; // Do not specify <source> tags - it may confuse browser.
            $isaudio = false; // Just in case.
        } else if ($flashtech) {
            $datasetup[] = '"techOrder": ["flash", "html5"]';
        }

        // Add a language.
        if ($this->language) {
            $datasetup[] = '"language": "' . $this->language . '"';
        }

        // Set responsive option.
        if ($responsive) {
            $datasetup[] = '"fluid": true';
        }

        if ($isaudio && !$hastracks) {
            // We don't need a full screen toggle for the audios (except when tracks are present).
            $datasetup[] = '"controlBar": {"fullscreenToggle": false}';
        }

        if ($isaudio && !$height && !$hastracks && !$hasposter) {
            // Hide poster area for audios without tracks or poster.
            // See discussion on https://github.com/videojs/video.js/issues/2777 .
            // Maybe TODO: if there are only chapter tracks we still don't need poster area.
            $datasetup[] = '"aspectRatio": "1:0"';
        }

        // Attributes for the video/audio tag.
        // We use data-setup-lazy as the attribute name for the config instead of
        // data-setup because data-setup will cause video.js to load the player as soon as the library is loaded,
        // which is BEFORE we have a chance to load any additional libraries (youtube).
        // The data-setup-lazy is just a tag name that video.js does not recognise so we can manually initialise
        // it when we are sure the dependencies are loaded.
        static $playercounter = 1;
        $attributes = [
            'data-setup-lazy' => '{' . join(', ', $datasetup) . '}',
            'id' => 'id_videojs_' . uniqid() . '_' . $playercounter++,
            'class' => get_config('media_videojs', $isaudio ? 'audiocssclass' : 'videocssclass')
        ];

        if (!$responsive) {
            // Note we ignore limitsize setting if not responsive.
            parent::pick_video_size($width, $height);
            $attributes += ['width' => $width] + ($height ? ['height' => $height] : []);
        }

        if (core_useragent::is_ios(10)) {
            // Hides native controls and plays videos inline instead of fullscreen,
            // see https://github.com/videojs/video.js/issues/3761 and
            // https://github.com/videojs/video.js/issues/3762 .
            // iPhone with iOS 9 still displays double controls and plays fullscreen.
            // iPhone with iOS before 9 display only native controls.
            $attributes += ['playsinline' => 'true'];
        }

        if ($text !== null) {
            // Original text already had media tag - add necessary attributes and replace sources
            // with the supported URLs only.
            if (($class = self::get_attribute($text, 'class')) !== null) {
                $attributes['class'] .= ' ' . $class;
            }
            $text = self::remove_attributes($text, ['id', 'width', 'height', 'class']);
            if (self::get_attribute($text, 'title') === null) {
                $attributes['title'] = $title;
            }
            $text = self::add_attributes($text, $attributes);
            $text = self::replace_sources($text, $sources);
        } else {
            // Create <video> or <audio> tag with necessary attributes and all sources.
            // We don't want fallback to another player because list_supported_urls() is already smart.
            // Otherwise we could end up with nested <audio> or <video> tags. Fallback to link only.
            $attributes += ['preload' => 'auto', 'controls' => 'true', 'title' => $title];
            $text = html_writer::tag($isaudio ? 'audio' : 'video', $sources . self::LINKPLACEHOLDER, $attributes);
        }

        // Limit the width of the video if width is specified.
        // We do not do it in the width attributes of the video because it does not work well
        // together with responsive behavior.
        if ($responsive) {
            self::pick_video_size($width, $height);
            if ($width) {
                $text = html_writer::div($text, null, ['style' => 'max-width:' . $width . 'px;']);
            }
        }

        return html_writer::div($text, 'mediaplugin mediaplugin_videojs');
    }