private function buildImgixImage($id, $size, $params = null, $skipParams = false, $mergeParams = null, $newSize = null)
 {
     if (is_array($size)) {
         return $this->buildSizedImgixImage($id, $size);
     }
     $mimetype = get_post_mime_type($id);
     $meta = wp_get_attachment_metadata($id);
     if (!$meta || empty($meta)) {
         return false;
     }
     $imgix = new Imgix\UrlBuilder($this->imgixDomains, $this->useHTTPS);
     if ($this->signingKey) {
         $imgix->setSignKey($this->signingKey);
     }
     if ($size == 'full' && !$newSize) {
         if (!$params) {
             if (isset($meta['imgix-params'])) {
                 $params = $meta['imgix-params'];
             } else {
                 $params = [];
             }
         }
         $params = $this->buildImgixParams($params, $mimetype);
         if (!isset($meta['file'])) {
             $cat = 'cool';
             return null;
         }
         $result = [$imgix->createURL(str_replace('%2F', '/', urlencode($meta['file'])), $skipParams ? [] : $params), $meta['width'], $meta['height'], false];
         return $result;
     }
     if ($newSize) {
         $sizeInfo = $newSize;
     } else {
         $sizeInfo = ilab_get_image_sizes($size);
     }
     if (!$sizeInfo) {
         return false;
     }
     $metaSize = null;
     if (isset($meta['sizes'][$size])) {
         $metaSize = $meta['sizes'][$size];
     }
     if (!$params) {
         // get the settings for this image at this size
         if (isset($meta['imgix-size-params'][$size])) {
             $params = $meta['imgix-size-params'][$size];
         }
         if (!$params || count($params) == 0) {
             $presets = get_option('ilab-imgix-presets');
             $sizePresets = get_option('ilab-imgix-size-presets');
             if ($presets && $sizePresets && isset($sizePresets[$size]) && isset($presets[$sizePresets[$size]])) {
                 $params = $presets[$sizePresets[$size]]['settings'];
             }
         }
         // still no parameters?  use any that may have been assigned to the full size image
         if ((!$params || count($params) == 0) && isset($meta['imgix-params'])) {
             $params = $meta['imgix-params'];
         } else {
             if (!$params) {
                 // too bad so sad
                 $params = [];
             }
         }
     }
     if ($sizeInfo['crop']) {
         $params['w'] = $sizeInfo['width'] ?: $sizeInfo['height'];
         $params['h'] = $sizeInfo['height'] ?: $sizeInfo['width'];
         $params['fit'] = 'crop';
         if ($metaSize) {
             $metaSize = $meta['sizes'][$size];
             if (isset($metaSize['crop'])) {
                 $metaSize['crop']['x'] = round($metaSize['crop']['x']);
                 $metaSize['crop']['y'] = round($metaSize['crop']['y']);
                 $metaSize['crop']['w'] = round($metaSize['crop']['w']);
                 $metaSize['crop']['h'] = round($metaSize['crop']['h']);
                 $params['rect'] = implode(',', $metaSize['crop']);
             }
         }
         // we don't want to scale animated gifs AT ALL on the front end
         if ($mimetype == 'image/gif' && !is_admin()) {
             $imageW = $meta['width'];
             $imageH = $meta['height'];
             $pw = $params['w'];
             $ph = $params['h'];
             if ($pw > $imageW || $ph > $imageH) {
                 $newSize = sizeToFitSize($pw, $ph, $imageW, $imageH, false);
                 $params['w'] = $newSize[0];
                 $params['h'] = $newSize[1];
             }
         }
     } else {
         $newSize = sizeToFitSize($meta['width'], $meta['height'], $sizeInfo['width'] ?: 10000, $sizeInfo['height'] ?: 10000);
         $params['w'] = $newSize[0];
         $params['h'] = $newSize[1];
         $params['fit'] = 'scale';
     }
     if ($mergeParams && is_array($mergeParams)) {
         $params = array_merge($params, $mergeParams);
     }
     if (!isset($params['fm'])) {
         if ($mimetype == 'image/gif') {
             $params['fm'] = 'gif';
         } else {
             if (!$this->autoFormat && $mimetype == 'image/png') {
                 $params['fm'] = 'png';
             } else {
                 $params['fm'] = 'pjpg';
             }
         }
     }
     if ($size && !is_array($size)) {
         $params['wpsize'] = $size;
     }
     $params = $this->buildImgixParams($params, $mimetype);
     $result = [$imgix->createURL(str_replace('%2F', '/', urlencode($meta['file'])), $params), $params['w'], $params['h'], false];
     return $result;
 }
 public function resize($max_w, $max_h, $crop = false)
 {
     error_log("[image-editor] Resize width:{$max_w} height:{$max_h} crop:{$crop}");
     if ($this->size['width'] == $max_w && $this->size['height'] == $max_h) {
         error_log("[image-editor] Same size. Exiting resize.");
         return true;
     }
     if (!$crop) {
         $newSize = sizeToFitSize($this->size['width'], $this->size['height'], $max_w, $max_h);
         list($newWidth, $newHeight) = $newSize;
         error_log("[image-editor] New size, width:{$newWidth} height:{$newHeight}");
         return $this->update_size($newWidth, $newHeight);
     } else {
         $newSize = sizeToFitSize($max_w, $max_h, $this->size['width'], $this->size['height']);
         $width = $this->size['width'];
         $height = $this->size['height'];
         list($newWidth, $newHeight) = $newSize;
         $x = round($width / 2 - $newWidth / 2);
         $y = round($height / 2 - $newHeight / 2);
         return $this->crop($x, $y, $newWidth, $newHeight, $max_w, $max_h, false);
     }
 }