public static function populateFromAsset(AssetFileModel $asset)
 {
     if ($asset->kind === 'json' && strpos($asset->filename, EmbeddedAssetsPlugin::getFileNamePrefix(), 0) === 0) {
         try {
             $url = $asset->getUrl();
             if (!UrlHelper::isAbsoluteUrl($url)) {
                 $protocol = craft()->request->isSecureConnection() ? 'https' : 'http';
                 $url = UrlHelper::getUrlWithProtocol($url, $protocol);
             }
             // See http://stackoverflow.com/questions/272361/how-can-i-handle-the-warning-of-file-get-contents-function-in-php
             $rawData = @file_get_contents($url);
             if ($rawData) {
                 $data = JsonHelper::decode($rawData);
                 if ($data['__embeddedasset__']) {
                     unset($data['__embeddedasset__']);
                     $embed = new EmbeddedAssetsModel();
                     $embed->id = $asset->id;
                     foreach ($data as $key => $value) {
                         $embed->{$key} = $value;
                     }
                     return $embed;
                 }
             }
         } catch (\Exception $e) {
             return null;
         }
     }
     return null;
 }
 public function readAssetFile(AssetFileModel $asset)
 {
     $url = $asset->getUrl();
     if (!UrlHelper::isAbsoluteUrl($url)) {
         $protocol = craft()->request->isSecureConnection() ? 'https' : 'http';
         $url = UrlHelper::getUrlWithProtocol($url, $protocol);
     }
     return $this->_readExternalFile($url);
 }
 /**
  * Create the 2x image.
  *
  * @param \Craft\AssetFileModel      $image
  * @param \Craft\AssetTransformModel $transform
  * @return string                    $markup
  */
 protected function create2xImage(AssetFileModel $image, AssetTransformModel $transform)
 {
     // Grab sizes as int.
     $originalWidth = (int) $image->getWidth(false);
     $transformWidth = (int) $transform->width;
     $transformHeight = (int) $transform->height;
     // Set transform params, uses params set in Craft.
     $params = ['mode' => $transform->mode, 'width' => $transformWidth * 2, 'height' => $transformHeight * 2, 'quality' => $transform->quality, 'position' => $transform->position];
     // Markup for the specified transform.
     $markup = $image->getUrl($transform->handle);
     // If original width is bigger than the 2x size for the specified transform, add the srcset.
     if ($originalWidth >= $transformWidth * 2) {
         $markup .= '" srcset="' . $image->getUrl($params) . ' 2x';
     }
     return $markup;
 }