/**
  * @param $url
  * @param null|int $width
  * @param null|int $height
  * @param null|int $size
  * @return ExtractedImage
  */
 public static function createFromUrl($url, $width = null, $height = null, $size = null, $fetchMetaData = false)
 {
     if (strlen(trim($url)) == 0) {
         return null;
     }
     if (StringHelper::startsWith($url, '//')) {
         $url = 'http:' . $url;
     }
     $curlHelper = new CurlHelper();
     if (!$curlHelper->exists($url)) {
         return null;
     }
     $image = new ExtractedImage();
     $image->setSource($url);
     if ((is_null($width) || is_null($height)) && $fetchMetaData) {
         $dimensions = getimagesize($url);
         if (!empty($dimensions) && is_array($dimensions) && count($dimensions) >= 2) {
             list($width, $height) = $dimensions;
         }
     }
     if (!is_null($width)) {
         $image->setWidth($width);
     }
     if (!is_null($height)) {
         $image->setHeight($height);
     }
     if (is_null($size) && $fetchMetaData) {
         $curlHelper = new CurlHelper();
         $size = $curlHelper->getContentLength($url);
     }
     $image->setSize($size);
     return $image;
 }
Example #2
0
 /**
  * @param string $embedUrl
  */
 public function setEmbedUrl($embedUrl)
 {
     $this->embedUrl = $embedUrl;
     if (StringHelper::startsWith($this->embedUrl, '//')) {
         $this->embedUrl = 'https:' . $this->embedUrl;
     }
 }
Example #3
0
 public function testStartsWith()
 {
     $this->assertTrue(\pmill\Extract\Helper\StringHelper::startsWith($this->testString, 'L'));
     $this->assertTrue(\pmill\Extract\Helper\StringHelper::startsWith($this->testString, 'Lo'));
     $this->assertTrue(\pmill\Extract\Helper\StringHelper::startsWith($this->testString, 'Lor'));
     $this->assertTrue(\pmill\Extract\Helper\StringHelper::startsWith($this->testString, 'Lore'));
     $this->assertTrue(\pmill\Extract\Helper\StringHelper::startsWith($this->testString, 'Lorem'));
     $this->assertFalse(\pmill\Extract\Helper\StringHelper::startsWith($this->testString, 'o'));
     $this->assertFalse(\pmill\Extract\Helper\StringHelper::startsWith($this->testString, 'or'));
 }