Create an Media Item of Flash, Youtube or Quicktime
@param $src
@param $windowWidth
@param $windowHeight
@param $thumb
@param $title
@param $caption
@param $width
@param $height
@return XmlnukeMediaItem
196132
public static function EmbedFactory($src, $windowWidth, $windowHeight, $thumb="", $title = "", $caption="", $width="", $height="")
	{
		/*
		if (strpos($src, "?") !== false)
		{
			$src .= "&amp;";
		}
		else
		{
			$src .= "?";
		}
		$src .= "width=$windowWidth&amp;height=$windowHeight";
		*/

		return new XmlnukeMediaItem($src, $thumb, $title, $caption, $width, $height);
	}
698986
public function create($width = null, $height = null)
    {
        $this->width  = ($width)  ? $width : $this->width;
        $this->height = ($height) ? $height : $this->height;

        $imageType    = $this->getImageType();
        $createFunc   = ($imageType === 'gif') ? 'imagecreate' : 'imagecreatetruecolor';
        $this->image  = $createFunc($this->width, $this->height);

        $bgColor = $this->backgroundColor;

        $backgroundColor = imagecolorallocate($this->image, $bgColor[0], $bgColor[1], $bgColor[2]);

        imagefilledrectangle($this->image, 0, 0, $this->width, $this->height, $backgroundColor);

        $this->drawText();

        if ($this->drawBorder)
        {
            $this->drawBorder();
        }

        if ($this->drawLine)
        {
            $this->drawLine();
        }

        if ($this->drawPixel)
        {
            $this->drawPixel();
        }

        return $this;
    }
758384
public function htmlimg($src, array $attribs = array(), $internal = true)
    {
        if (isset($attribs['src'])) {
            unset($attribs['src']);
        }

        if ($internal) {
            $src = $this->view->media($src);
        }

        $xhtml = '<img ';
        $xhtml .= 'src="' . $src . '" ';
        $xhtml .= $this->_htmlAttribs($attribs);
        $xhtml .= $this->getClosingBracket();

        return $xhtml;
    }
706897
public static function frameFiles($field, $title, $src, array $value = [])
    {
        return self::frame($field, $title, $src, $value, Frame::TYPE_FILE);
    }
661594
public static function frameFileOne($field, $title, $src, $value = '')
    {
        return self::frame($field, $title, $src, (string)$value, Frame::TYPE_FILE);
    }
866072
public function addEmbed($src, $windowWidth, $windowHeight, $thumb="", $title = "", $caption="", $width="", $height="")
	{
		$this->addXmlnukeObject(XmlnukeMediaItem::EmbedFactory($src, $windowWidth, $windowHeight, $thumb, $title, $caption, $width, $height));
	}
986418
function WhammyRecorderHelper(mediaStream, root) {
    this.record = function(timeSlice) {
        if (!this.width) {
            this.width = 320;
        }
        if (!this.height) {
            this.height = 240;
        }

        if (this.video && this.video instanceof HTMLVideoElement) {
            if (!this.width) {
                this.width = video.videoWidth || video.clientWidth || 320;
            }
            if (!this.height) {
                this.height = video.videoHeight || video.clientHeight || 240;
            }
        }

        if (!this.video) {
            this.video = {
                width: this.width,
                height: this.height
            };
        }

        if (!this.canvas || !this.canvas.width || !this.canvas.height) {
            this.canvas = {
                width: this.width,
                height: this.height
            };
        }

        canvas.width = this.canvas.width;
        canvas.height = this.canvas.height;

        // setting defaults
        if (this.video && this.video instanceof HTMLVideoElement) {
            this.isHTMLObject = true;
            video = this.video.cloneNode();
        } else {
            video = document.createElement('video');
            video.src = URL.createObjectURL(mediaStream);

            video.width = this.video.width;
            video.height = this.video.height;
        }

        video.muted = true;
        video.play();

        lastTime = new Date().getTime();
        whammy = new Whammy.Video(root.speed, root.quality);

        console.log('canvas resolutions', canvas.width, '*', canvas.height);
        console.log('video width/height', video.width || canvas.width, '*', video.height || canvas.height);

        drawFrames();
    };

    this.clearOldRecordedFrames = function() {
        whammy.frames = [];
    };

    var requestDataInvoked = false;
    this.requestData = function() {
        if (isPaused) {
            return;
        }

        if (!whammy.frames.length) {
            requestDataInvoked = false;
            return;
        }

        requestDataInvoked = true;
        // clone stuff
        var internalFrames = whammy.frames.slice(0);

        // reset the frames for the new recording

        whammy.frames = dropBlackFrames(internalFrames, -1);

        whammy.compile(function(whammyBlob) {
            root.ondataavailable(whammyBlob);
            console.debug('video recorded blob size:', bytesToSize(whammyBlob.size));
        });

        whammy.frames = [];

        requestDataInvoked = false;
    };

    var isOnStartedDrawingNonBlankFramesInvoked = false;

    function drawFrames() {
        if (isPaused) {
            lastTime = new Date().getTime();
            setTimeout(drawFrames, 500);
            return;
        }

        if (isStopDrawing) {
            return;
        }

        if (requestDataInvoked) {
            return setTimeout(drawFrames, 100);
        }

        var duration = new Date().getTime() - lastTime;
        if (!duration) {
            return drawFrames();
        }

        // via webrtc-experiment#206, by Jack i.e. @Seymourr
        lastTime = new Date().getTime();

        if (!self.isHTMLObject && video.paused) {
            video.play(); // Android
        }

        context.drawImage(video, 0, 0, canvas.width, canvas.height);

        if (!isStopDrawing) {
            whammy.frames.push({
                duration: duration,
                image: canvas.toDataURL('image/webp')
            });
        }

        if (!isOnStartedDrawingNonBlankFramesInvoked && !isBlankFrame(whammy.frames[whammy.frames.length - 1])) {
            isOnStartedDrawingNonBlankFramesInvoked = true;
            root.onStartedDrawingNonBlankFrames();
        }

        setTimeout(drawFrames, 10);
    }

    var isStopDrawing = false;

    this.stop = function() {
        isStopDrawing = true;
        this.requestData();
        this.onstop();
    };

    var canvas = document.createElement('canvas');
    var context = canvas.getContext('2d');

    var video;
    var lastTime;
    var whammy;

    var self = this;

    function isBlankFrame(frame, _pixTolerance, _frameTolerance) {
        var localCanvas = document.createElement('canvas');
        localCanvas.width = canvas.width;
        localCanvas.height = canvas.height;
        var context2d = localCanvas.getContext('2d');

        var sampleColor = {
            r: 0,
            g: 0,
            b: 0
        };
        var maxColorDifference = Math.sqrt(
            Math.pow(255, 2) +
            Math.pow(255, 2) +
            Math.pow(255, 2)
        );
        var pixTolerance = _pixTolerance && _pixTolerance >= 0 && _pixTolerance <= 1 ? _pixTolerance : 0;
        var frameTolerance = _frameTolerance && _frameTolerance >= 0 && _frameTolerance <= 1 ? _frameTolerance : 0;

        var matchPixCount, endPixCheck, maxPixCount;

        var image = new Image();
        image.src = frame.image;
        context2d.drawImage(image, 0, 0, canvas.width, canvas.height);
        var imageData = context2d.getImageData(0, 0, canvas.width, canvas.height);
        matchPixCount = 0;
        endPixCheck = imageData.data.length;
        maxPixCount = imageData.data.length / 4;

        for (var pix = 0; pix < endPixCheck; pix += 4) {
            var currentColor = {
                r: imageData.data[pix],
                g: imageData.data[pix + 1],
                b: imageData.data[pix + 2]
            };
            var colorDifference = Math.sqrt(
                Math.pow(currentColor.r - sampleColor.r, 2) +
                Math.pow(currentColor.g - sampleColor.g, 2) +
                Math.pow(currentColor.b - sampleColor.b, 2)
            );
            // difference in color it is difference in color vectors (r1,g1,b1) <=> (r2,g2,b2)
            if (colorDifference <= maxColorDifference * pixTolerance) {
                matchPixCount++;
            }
        }

        if (maxPixCount - matchPixCount <= maxPixCount * frameTolerance) {
            return false;
        } else {
            return true;
        }
    }

    function dropBlackFrames(_frames, _framesToCheck, _pixTolerance, _frameTolerance) {
        var localCanvas = document.createElement('canvas');
        localCanvas.width = canvas.width;
        localCanvas.height = canvas.height;
        var context2d = localCanvas.getContext('2d');
        var resultFrames = [];

        var checkUntilNotBlack = _framesToCheck === -1;
        var endCheckFrame = (_framesToCheck && _framesToCheck > 0 && _framesToCheck <= _frames.length) ?
            _framesToCheck : _frames.length;
        var sampleColor = {
            r: 0,
            g: 0,
            b: 0
        };
        var maxColorDifference = Math.sqrt(
            Math.pow(255, 2) +
            Math.pow(255, 2) +
            Math.pow(255, 2)
        );
        var pixTolerance = _pixTolerance && _pixTolerance >= 0 && _pixTolerance <= 1 ? _pixTolerance : 0;
        var frameTolerance = _frameTolerance && _frameTolerance >= 0 && _frameTolerance <= 1 ? _frameTolerance : 0;
        var doNotCheckNext = false;

        for (var f = 0; f < endCheckFrame; f++) {
            var matchPixCount, endPixCheck, maxPixCount;

            if (!doNotCheckNext) {
                var image = new Image();
                image.src = _frames[f].image;
                context2d.drawImage(image, 0, 0, canvas.width, canvas.height);
                var imageData = context2d.getImageData(0, 0, canvas.width, canvas.height);
                matchPixCount = 0;
                endPixCheck = imageData.data.length;
                maxPixCount = imageData.data.length / 4;

                for (var pix = 0; pix < endPixCheck; pix += 4) {
                    var currentColor = {
                        r: imageData.data[pix],
                        g: imageData.data[pix + 1],
                        b: imageData.data[pix + 2]
                    };
                    var colorDifference = Math.sqrt(
                        Math.pow(currentColor.r - sampleColor.r, 2) +
                        Math.pow(currentColor.g - sampleColor.g, 2) +
                        Math.pow(currentColor.b - sampleColor.b, 2)
                    );
                    // difference in color it is difference in color vectors (r1,g1,b1) <=> (r2,g2,b2)
                    if (colorDifference <= maxColorDifference * pixTolerance) {
                        matchPixCount++;
                    }
                }
            }

            if (!doNotCheckNext && maxPixCount - matchPixCount <= maxPixCount * frameTolerance) {
                // console.log('removed black frame : ' + f + ' ; frame duration ' + _frames[f].duration);
            } else {
                // console.log('frame is passed : ' + f);
                if (checkUntilNotBlack) {
                    doNotCheckNext = true;
                }
                resultFrames.push(_frames[f]);
            }
        }

        resultFrames = resultFrames.concat(_frames.slice(endCheckFrame));

        if (resultFrames.length <= 0) {
            // at least one last frame should be available for next manipulation
            // if total duration of all frames will be < 1000 than ffmpeg doesn't work well...
            resultFrames.push(_frames[_frames.length - 1]);
        }

        return resultFrames;
    }

    var isPaused = false;

    this.pause = function() {
        isPaused = true;
    };

    this.resume = function() {
        isPaused = false;
    };

    this.onstop = function() {};
}
329702
public function setVideoBackground($src, $poster = null)
    {
        $this->attributes->addAttributeClass('jumbotron-video');

        $video = new Element('video', 'jumbotron-video');

        if (isset($poster)) {
            $video->attributes->addAttribute('poster', $poster);
        }

        $video->attributes->addAttribute('width', '100%');
        $video->attributes->addAttribute('preload', 'auto');
        $video->attributes->addAttribute('loop', null);
        $video->attributes->addAttribute('autoplay', null);
        $video->attributes->addAttribute('muted', null);

        $source = new Element('source', 'jumbotron-video-source');

        if (is_file($src)) {
            $src = path_to_url($src);
        }

        $source->attributes->addAttribute('src', $src);
        $source->attributes->addAttribute('type', 'video/webm');

        $video->textContent->push($source->render());

        $this->childNodes->prepend($video);

        return $this;
    }
357043
public function create_simple_html_dom( $src ){
		// Simple HTML DOM
		$simple_html_dom = str_get_html(
			$src ,
			true, // $lowercase
			true, // $forceTagsClosed
			DEFAULT_TARGET_CHARSET, // $target_charset
			false, // $stripRN
			DEFAULT_BR_TEXT, // $defaultBRText
			DEFAULT_SPAN_TEXT // $defaultSpanText
		);
		return $simple_html_dom;
	}
368732
public static function addFooterMediaElement($footerCount, $src, PHPWord_Section_MemoryImage $memoryImage = null) {
		$mediaId = md5($src);
		$key = 'footer'.$footerCount;
		
		if(!array_key_exists($key, self::$_footerMedia)) {
			self::$_footerMedia[$key] = array();
		}
		
		if(!array_key_exists($mediaId, self::$_footerMedia[$key])) {
			$cImg = self::countFooterMediaElements($key);
			$rID = $cImg + 1;
			
			$cImg++;
			$inf = pathinfo($src);
			$isMemImage = (substr(strtolower($inf['extension']), 0, 3) == 'php') ? true : false;
			
			$media = array();
			if($isMemImage) {
				$ext = $memoryImage->getImageExtension();
				$media['isMemImage'] = true;
				$media['createfunction'] = $memoryImage->getImageCreateFunction();
				$media['imagefunction'] = $memoryImage->getImageFunction();
			} else {
				$ext = $inf['extension'];
				if($ext == 'jpeg') { // Office crashes when adding a jpEg Image, so rename to jpg
					$ext = 'jpg';
				}
			}
			$file = 'image'.$cImg.'.'.strtolower($ext);
			
			$media['source'] = $src;
			$media['target'] = 'media/'.$key.'_'.$file;
			$media['type'] = 'image';
			$media['rID'] = $rID;
			
			self::$_footerMedia[$key][$mediaId] = $media;
			
			return $rID;
		} else {
			return self::$_footerMedia[$key][$mediaId]['rID'];
		}
	}
179705
public static function YouTubeHandler($arguments, $caption = null)
    {
        // If there's no ID, just stop.
        if (empty($arguments['id'])) {
            return null;
        }
        /*		 * * SET DEFAULTS ** */
        $defaults = array(
            'YouTubeID' => $arguments['id'],
            'autoplay'  => false,
            'caption'   => $caption ? Convert::raw2xml($caption) : false,
            'width'     => 640,
            'height'    => 385,
        );

        //overide the defaults with the arguments supplied
        $customise = array_merge($defaults, $arguments);
        $template = new SSViewer('YouTube');

        return $template->process(new ArrayData($customise));
    }
1220651
public function createThumbnail($savePath, $newImageName, $srcImageFile)
    {
        $getImageFile = $this->resizeImage($savePath, $srcImageFile, 'tmb_'.$newImageName, 250, 250);
        
        return $getImageFile;
    }
892305
public function addImage($src, $style = null) {
		$image = new PHPWord_Section_Image($src, $style);
		
		if(!is_null($image->getSource())) {
			if($this->_insideOf == 'section') {
				$rID = PHPWord_Media::addSectionMediaElement($src, 'image');
			} elseif($this->_insideOf == 'header') {
				$rID = PHPWord_Media::addHeaderMediaElement($this->_pCount, $src);
			} elseif($this->_insideOf == 'footer') {
				$rID = PHPWord_Media::addFooterMediaElement($this->_pCount, $src);
			}
			$image->setRelationId($rID);
			
			$this->_elementCollection[] = $image;
			return $image;
		} else {
			trigger_error('Source does not exist or unsupported image type.');
		}
	}
1109946
public function create($mixed, $savePath, $width, $height, $fit = false, $format = false)
    {
        if ($format === false) {
            $format = $this->getThumbnailsFormat();
        }
        switch ($format) {
            case ThumbnailFormatService::FORMAT_AUTO:
                $format = $this->app->make(ThumbnailFormatService::class)->getAutomaticFormatForFile($savePath);
                break;
        }
        $thumbnailOptions = [
            'jpeg_quality' => $this->getJpegCompression(),
            'png_compression_level' => $this->getPngCompression(),
        ];
        $filesystem = $this->getStorageLocation()->getFileSystemObject();

        if ($mixed instanceof ImageInterface) {
            $image = $mixed;
        } else {
            $image = Image::open($mixed);
        }
        if ($fit) {
            $thumb = $image->thumbnail(new Box($width, $height), ImageInterface::THUMBNAIL_OUTBOUND);
            $filesystem->write(
                $savePath,
                $thumb->get($format, $thumbnailOptions)
            );
        } else {
            if ($height < 1) {
                $thumb = $image->thumbnail($image->getSize()->widen($width));
            } elseif ($width < 1) {
                $thumb = $image->thumbnail($image->getSize()->heighten($height));
            } else {
                $thumb = $image->thumbnail(new Box($width, $height));
            }
            $filesystem->write(
                $savePath,
                $thumb->get($format, $thumbnailOptions)
            );
        }
    }
419610
protected function do_resize(\stdClass $src, $width, $height) {

		$src->resource->resizeImage($width, $height, \Imagick::FILTER_CATROM, 1, FALSE);
		$src->resource->convolveImage([-1, -0.8, -1, -0.8, 16, -0.8, -1, -0.8, -1]);
		
		$src->width		= $width;
		$src->height	= $height;

		return $src;
		
	}
997966
public static function addHeaderMediaElement($headerCount, $src, PHPWord_Section_MemoryImage $memoryImage = null) {
		$mediaId = md5($src);
		$key = 'header'.$headerCount;
		
		if(!array_key_exists($key, self::$_headerMedia)) {
			self::$_headerMedia[$key] = array();
		}
		
		if(!array_key_exists($mediaId, self::$_headerMedia[$key])) {
			$cImg = self::countHeaderMediaElements($key);
			$rID = $cImg + 1;
			
			$cImg++;
			$inf = pathinfo($src);
			$isMemImage = (substr(strtolower($inf['extension']), 0, 3) == 'php') ? true : false;
			
			$media = array();
			if($isMemImage) {
				$ext = $memoryImage->getImageExtension();
				$media['isMemImage'] = true;
				$media['createfunction'] = $memoryImage->getImageCreateFunction();
				$media['imagefunction'] = $memoryImage->getImageFunction();
			} else {
				$ext = $inf['extension'];
				if($ext == 'jpeg') { // Office crashes when adding a jpEg Image, so rename to jpg
					$ext = 'jpg';
				}
			}
			$file = 'image'.$cImg.'.'.strtolower($ext);
			
			$media['source'] = $src;
			$media['target'] = 'media/'.$key.'_'.$file;
			$media['type'] = 'image';
			$media['rID'] = $rID;
			
			self::$_headerMedia[$key][$mediaId] = $media;
			
			return $rID;
		} else {
			return self::$_headerMedia[$key][$mediaId]['rID'];
		}
	}
1039200
public function iFrame($maxwidth = '100%', $height = '56%')
    {
        $url = $this->getIFrameURL();
        if (!$url) {
            return false;
        }
        if (is_numeric($maxwidth)) {
            $maxwidth .= 'px';
        }
        if (is_numeric($height)) {
            $height .= 'px';
        }
        return $this->customise([
            'URL'      => $url,
            'MaxWidth' => $maxwidth,
            'Height'   => $height,
        ])->renderWith('Axllent\\FormFields\\Layout\\VideoIframe');
    }