Filters whether to preempt the output of image_downsize().  (https://core.trac.wordpress.org/browser/tags/4.8/src/wp-includes/media.php#L201)
@param $fail
@param $id
@param $size
@return array
@throws StorageException
764372
public function imageDownsize($fail, $id, $size) {
		if(apply_filters('ilab_imgix_enabled', false)) {
			return $fail;
		}

		return $this->forcedImageDownsize($fail, $id, $size);
	}
269708
public function getImage($attachment_id, $size = "post-thumbnail", $placeholder = true)
    {
        $sizes = $this->getConfig("image-sizes");

        if (isset($sizes[$size]) && $placeholder) {
            $image = "//placehold.it/" . $sizes[$size]["width"] . "x" . $sizes[$size]["height"];
        } else {
            $image = false;
        }

        $imgData = wp_get_attachment_image_src($attachment_id, $size);
        if ($imgData && is_array($imgData) && isset($imgData[0]) && $imgData[0]):
            $image = $imgData[0];
        endif;

        return $image;
    }
12321
public function getSize($id = 0)
    {
        $id = $id ? $id : null;
        return $this->_protocol->getList($id);
    }
1086556
private function removeFromMetaData($id) {
        $storageFileName = $this->directory . $id . '.info';
        if (file_exists($storageFileName) && is_writable($storageFileName)) {
            unset($storageFileName);
            return true;
        }
        return false;
    }
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);
    }
1370022
private function buildSizedImgixImage($id, $size) {
		$meta = wp_get_attachment_metadata($id);
		if(!$meta || empty($meta)) {
			return false;
		}

		if(!isset($meta['s3'])) {
			return [];
		}

		$imgix = new UrlBuilder($this->imgixDomains, $this->useHTTPS);

		if($this->signingKey) {
			$imgix->setSignKey($this->signingKey);
		}


		$is_crop = ((count($size) >= 3) && ($size[2] == 'crop'));
		if (!$is_crop && $this->shouldCrop) {
		    $this->shouldCrop = false;
		    $is_crop = true;
        }

        if ($is_crop && (($size[0] === 0) || ($size[1] === 0))) {
		    if ($size[0] === 0) {
		        $size[0] = 10000;
            } else {
		        $size[1] = 10000;
            }

		    $is_crop = false;
        }

		if(isset($size['width'])) {
			$size = [
				$size['width'],
				$size['height']
			];
		}

		$params = [
			'fit' => ($is_crop) ? 'crop' : 'fit',
			'w' => $size[0],
			'h' => $size[1],
			'fm' => 'jpg'
		];
		$params = apply_filters('ilab-imgix-filter-parameters', $params, $size, $id, $meta);

		$imageFile = (isset($meta['s3'])) ? $meta['s3']['key'] : $meta['file'];

		$result = [
			$imgix->createURL(str_replace('%2F', '/', urlencode($imageFile)), $params),
			$size[0],
			$size[1]
		];

		return $result;
	}
1252719
public function getResizer($id)
    {
        if (!isset($this->resizers[$id])) {
            throw new \LogicException(sprintf('Resizer with id: "%s" is not attached.', $id));
        }

        return $this->resizers[$id];
    }
160196
private function buildImgixImage($id, $size, $params = null, $skipParams = false, $mergeParams = null, $newSize = null, $newMeta=null) {
		if(is_array($size)) {
			return $this->buildSizedImgixImage($id, $size);
		}

		$mimetype = get_post_mime_type($id);

        if (!$this->renderPDF && ($mimetype == 'application/pdf')) {
            return false;
        }

		$meta = wp_get_attachment_metadata($id);
		if(!$meta || empty($meta)) {
			if(($this->renderPDF && ($mimetype == 'application/pdf')) || ($this->enabledAlternativeFormats && ($mimetype == 'application/vnd.adobe.illustrator'))) {
				$meta = get_post_meta($id, 'ilab_s3_info', true);
			}

			if(!$meta || empty($meta)) {
			    if (!empty($newMeta)) {
			        $meta = $newMeta;
                } else {
				    return false;
                }
			}
		}

		if(!isset($meta['s3'])) {
			if(($this->renderPDF && ($mimetype == 'application/pdf')) || ($this->enabledAlternativeFormats && ($mimetype == 'application/vnd.adobe.illustrator'))) {
				$meta = get_post_meta($id, 'ilab_s3_info', true);
			} else {
				return false;
			}
		}

		$imgix = new UrlBuilder($this->imgixDomains, $this->useHTTPS);

		if($this->signingKey) {
			$imgix->setSignKey($this->signingKey);
		}

		if($size == 'full' && !$newSize) {
			if(!isset($meta['width']) || !isset($meta['height'])) {
				return false;
			}

			if(!$params) {
				if(isset($meta['imgix-params'])) {
					$params = $meta['imgix-params'];
				} else {
					$params = [];
				}
			}

			$params = $this->buildImgixParams($params, $mimetype);
			$params = apply_filters('ilab-imgix-filter-parameters', $params, $size, $id, $meta);

			if(!isset($meta['file'])) {
				return null;
			}

			$imageFile = (isset($meta['s3'])) ? $meta['s3']['key'] : $meta['file'];

			$result = [
				$imgix->createURL(str_replace('%2F', '/', urlencode($imageFile)), ($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];
		}

		$doCrop = !empty($sizeInfo['crop']);

		if(!$params) {
		    $sizeParams = (!empty($sizeInfo['imgix']) && is_array($sizeInfo['imgix'])) ? $sizeInfo['imgix'] : [];
		    $sizeCropParams = (isset($sizeParams['crop'])) ? $sizeParams['crop'] : [];
		    if (!empty($sizeCropParams)) {
                if (is_string($sizeCropParams)) {
                    $sizeCropParams = explode(',', $sizeCropParams);
                    unset($sizeParams['crop']);
                }

                $doCrop = true;
            }

            // get the settings for this image at this size
			if(isset($meta['imgix-size-params'][$size])) {
				$params = array_merge($sizeParams, $meta['imgix-size-params'][$size]);
			}


			if(!$params || (count($params) == 0)) // see if a preset has been globally assigned to a size and use that
			{
				$presets = get_option('ilab-imgix-presets');
				$sizePresets = get_option('ilab-imgix-size-presets');

				if($presets && $sizePresets && isset($sizePresets[$size]) && isset($presets[$sizePresets[$size]])) {
					$params = array_merge($sizeParams, $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 = array_merge($sizeParams, $meta['imgix-params']);
			} else if(!$params) // too bad so sad
			{
				$params = $sizeParams;
			}
		}

		if ($doCrop) {
			$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);
					$params['w'] = $newSize[0];
					$params['h'] = $newSize[1];
				}
			}

			if (isset($params['focalpoint'])) {
			    unset($params['rect']);

			    if ($params['focalpoint'] == 'entropy') {
				    $params['crop'] = 'entropy';
				    unset($params['fp-x']);
				    unset($params['fp-y']);
				    unset($params['fp-z']);
                } else if ($params['focalpoint'] == 'edges') {
				    $params['crop'] = 'edges';
				    unset($params['fp-x']);
				    unset($params['fp-y']);
				    unset($params['fp-z']);
                } else {
				    $params['crop'] = 'focalpoint';
				    if ($params['focalpoint'] == 'usefaces') {
					    unset($params['fp-x']);
					    unset($params['fp-y']);

					    if (isset($meta['faces'])) {
						    $faceindex = arrayPath($params,'faceindex', 0);
						    if ((count($meta['faces'])>1) && ($faceindex == 0)) {
							    $left = 900000;
							    $top = 900000;
							    $right = 0;
							    $bottom = 0;

							    foreach($meta['faces'] as $face) {
								    $bb = $face['BoundingBox'];
								    $left = min($left, $bb['Left']);
								    $top = min($top, $bb['Top']);
								    $right = max($right, $bb['Left'] + $bb['Width']);
								    $bottom = max($bottom, $bb['Top'] + $bb['Height']);
							    }

							    $params['fp-x'] = $left + (($right - $left) / 2.0);
							    $params['fp-y'] = $top + (($bottom - $top) / 2.0);
						    } else {
							    if ($faceindex == 0) {
								    $faceindex = 1;
							    }

							    $faceindex = min(count($meta['faces'])+1, $faceindex);
							    $bb = $meta['faces'][$faceindex - 1]['BoundingBox'];

							    $params['fp-x'] = $bb['Left'] + ($bb['Width'] / 2.0);
							    $params['fp-y'] = $bb['Top'] + ($bb['Height'] / 2.0);
						    }

					    } else {
						    unset($params['crop']);
						    unset($params['fp-z']);
					    }
				    }
                }
            } else {
				unset($params['fp-x']);
				unset($params['fp-y']);
				unset($params['fp-z']);

                $cropParams = [];

                if (!empty($sizeInfo['crop']) && is_array($sizeInfo['crop'])) {
                    list($cropX, $cropY) = $sizeInfo['crop'];
                    if (!empty($cropX) && ($cropX != 'center')) {
                        $cropParams[] = $cropX;
                    }
                    if (!empty($cropY) && ($cropY != 'center')) {
                        $cropParams[] = $cropY;
                    }
                }

                if (!empty($sizeCropParams)) {
                    $cropParams = array_merge($cropParams, $sizeCropParams);
                }

                if (!empty($cropParams)) {
                    $params['crop'] = implode(",", $cropParams);
                }
            }
		} else {
			$mw = !empty($meta['width']) ? $meta['width'] : 10000;
			$mh = !empty($meta['height']) ? $meta['height'] : 10000;

			$w = !empty($sizeInfo['width']) ? $sizeInfo['width'] : 10000;
			$h = !empty($sizeInfo['height']) ? $sizeInfo['height'] : 10000;

			$newSize = sizeToFitSize($mw, $mh, $w, $h);
			$params['w'] = $newSize[0];
			$params['h'] = $newSize[1];
			$params['fit'] = 'scale';

			unset($params['fp-x']);
			unset($params['fp-y']);
			unset($params['fp-z']);
		}

		unset($params['focalpoint']);
		unset($params['faceindex']);

		if($mergeParams && is_array($mergeParams)) {
			$params = array_merge($params, $mergeParams);
		}

		if($size && !is_array($size)) {
			$params['wpsize'] = $size;
		}

		$params = $this->buildImgixParams($params, $mimetype);
		$params = apply_filters('ilab-imgix-filter-parameters', $params, $size, $id, $meta);

		$imageFile = (isset($meta['s3'])) ? $meta['s3']['key'] : $meta['file'];

		$result = [
			$imgix->createURL(str_replace('%2F', '/', urlencode($imageFile)), $params),
			$params['w'],
			$params['h'],
			true
		];

		return $result;
	}
55147
public function filter_by_template_page( $sizes, $id = 0 ) {
		$template = get_page_template_slug( $id );
		if ( empty( $template ) ) {
			return $sizes;
		}
		$template_name = Formatter::to_filter_format( $template );
		return apply_filters( Formatter::katana_filter( $template_name ), $sizes );
	}
503887
public function destroy($id)
    {
        $image = $this->repository->find($id);

        if (is_file(storage_path($image->location))) {
            Storage::delete($image->location);
        } else {
            Storage::disk(Config::get('cms.storage-location', 'local'))->delete($image->location);
        }

        if (empty($image)) {
            Cms::notification('Image not found', 'warning');

            return redirect(route($this->routeBase.'.images.index'));
        }

        $image->forgetCache();
        $image->delete();

        Cms::notification('Image deleted successfully.', 'success');

        return redirect(route($this->routeBase.'.images.index'));
    }
543644
public function addImageSize(ImageSize $size)
	{
		if ($this->imageSizes->containsKey($size->getName())) {
			return false;
		} else {
			$this->imageSizes->set($size->getName(), $size);
			return true;
		}
	}
902779
public function truncate($size)
    {
        if($resource = $this->getResource())
        {
            if($this->isWritable()) {
                return @ftruncate($resource, $size);
            }
        }

        return false;
    }
549425
public function skip($size)
    {
        if ($size < 0) {
            throw new DomainAssertion('Size cannot be negative');
        }
        if ($size == 0) {
            return;
        }
        $this->checkStreamAvailable();
        fseek($this->fileDescriptor, $size, SEEK_CUR);
    }
41107
protected function _generateScaledImagesForId($id, $overwrite = false) {
        if (!$id) {
            return;
        }

        $imageModel = new Model_Image();
        $record     = $imageModel->fetchById($id);
        return $this->_generateScaledImagesForFilename($record->filename);
    }
447374
public static function iniSizeToBytes($size)
    {
        if (\is_numeric($size)) {
            return (int)$size;
        }

        $suffix = \strtoupper(\substr($size, -1));
        $strippedSize = \substr($size, 0, -1);

        if (!\is_numeric($strippedSize)) {
            throw new \InvalidArgumentException("$size is not a valid ini size");
        }

        if ($strippedSize <= 0) {
            throw new \InvalidArgumentException("Expect $size to be higher isn't zero or lower");
        }

        if ($suffix === 'K') {
            return $strippedSize * 1024;
        }
        if ($suffix === 'M') {
            return $strippedSize * 1024 * 1024;
        }
        if ($suffix === 'G') {
            return $strippedSize * 1024 * 1024 * 1024;
        }
        if ($suffix === 'T') {
            return $strippedSize * 1024  * 1024 * 1024 * 1024;
        }

        return (int)$size;
    }
513138
public function doResize($destination, $size, $cropX=0, $cropY=0, $resized=false)
    {
        if (($resource = $this->getResource()) == null) {
            return false;
        }

        $image     = imagecreatetruecolor($size['width'], $size['height']);
        $imageCopy = false;

        if ($resized) {
            $imageCopy = imagecopyresized($image, $resource, 0, 0, $cropX, $cropY, $size['width'], $size['height'], $size['width'], $size['height']);
        }
        else {
            $imageCopy = imagecopyresampled($image, $resource, 0, 0, $cropX, $cropY, $size['width'], $size['height'], $this->sourceWidth, $this->sourceHeight);
        }


        if ($imageCopy) {
            if ($this->save($image, $destination)) {
                imagedestroy($image);

                return true;
            }
            else {
                imagedestroy($image);

                return false;
            }
        }
        else {
            imagedestroy($image);

            return false;
        }
    }
331653
public static function getImage($id, $size = "moyen", $showDefault = true, $dimension = array('height'=>200,'width'=>200))
    {
        global $config;
        $req = "
            SELECT idImage
            FROM _personneImage
            WHERE idPersonne = '".mysql_real_escape_string($id)."'
        ";

        $res = $config->connexionBdd->requete($req);
        if ($fetch=mysql_fetch_object($res)) {
            $req = "
                SELECT dateUpload, idHistoriqueImage
                FROM historiqueImage
                WHERE idImage = '".$fetch->idImage."'
            ";
            $res = $config->connexionBdd->requete($req);
            $fetch = mysql_fetch_object($res);
            if (isset($fetch->idHistoriqueImage)) {
                if ($size=="resized") {
                    return "resizeImage.php?id=".$fetch->idHistoriqueImage."&height=".$dimension['height']."&width=".$dimension['width']."";
                }
                return $config->getUrlImage($size).$fetch->dateUpload.'/'.$fetch->idHistoriqueImage.'.jpg';
            }
        }
        if ($showDefault) {
            return "images/avatar/default.jpg";
        }

    }