获取图片可访问地址
如果是视频请返回视频的封面图片
@param string $file_id 文件id
@param int $width
@param int $height
@param bool $water
@param int $crop
@param int $blur
@return string
510998
public function getPicUrl($file_id,$width=0,$height=0,$water=false,$crop=1,$blur){
        return  $this->storage->getPicUrl($file_id,$width,$height,$water,$crop,$blur);
    }
768524
public function do_crop($width, $height, $offsetX = 0, $offsetY = 0)
    {
        $this->_image->cropImage($width, $height, $offsetX, $offsetY);
        $this->_image->setImagePage($width, $height, 0, 0);

        $this->_width = $this->_image->getImageWidth();
        $this->_height = $this->_image->getImageHeight();

        return $this;
    }
809262
public function generateThumbnail($id, $width, $height = null)
	{
		if ($height === null)
		{
			$height = $width;
		}

		$temp = $this->container->download($id);

		$img = new \Imagick($temp->getPath());
		$img->cropThumbnailImage($width, $height);
		$img->writeImage();

		return $this->container->upload($temp);
	}
783605
private function createImageKeepTransparency($width, $height)
    {
        $this->log("Creating a new working image width={$width}px, height={$height}px.");
        $img = imagecreatetruecolor($width, $height);
        imagealphablending($img, false);
        imagesavealpha($img, true);

        $index = $this->image
            ? imagecolortransparent($this->image)
            : -1;

        if ($index != -1) {

            imagealphablending($img, true);
            $transparent = imagecolorsforindex($this->image, $index);
            $color = imagecolorallocatealpha($img, $transparent['red'], $transparent['green'], $transparent['blue'], $transparent['alpha']);
            imagefill($img, 0, 0, $color);
            $index = imagecolortransparent($img, $color);
            $this->Log("Detected transparent color = " . implode(", ", $transparent) . " at index = $index");

        } elseif ($this->bgColorDefault) {

            $color = $this->getBackgroundColor($img);
            imagefill($img, 0, 0, $color);
            $this->Log("Filling image with background color.");
        }

        return $img;
    }
1141004
public function pathFilenameOfResizedImage($filename, $width, $height)
    {
        $path                      = $this->pathOfImagesResizedFolder();
        $filenameWithNoExtension   = $this->filenameWithNoExtension($filename);
        $filenameWithExtensionOnly = $this->filenameWithExtensionOnly($filename);

        $resizedFilename  = $path;
        $resizedFilename .= "/";
        $resizedFilename .= $filenameWithNoExtension;
        $resizedFilename .= '-';
        $resizedFilename .= $width;
        $resizedFilename .= 'x';
        $resizedFilename .= $height;
        $resizedFilename .= '.';
        $resizedFilename .= $filenameWithExtensionOnly;

        return $resizedFilename;
    }
104155
public function get_file_by_id($fileid) {
        global $DB;

        $sql = "SELECT ".self::instance_sql_fields('f', 'r')."
                  FROM {files} f
             LEFT JOIN {files_reference} r
                       ON f.referencefileid = r.id
                 WHERE f.id = ?";
        if ($filerecord = $DB->get_record_sql($sql, array($fileid))) {
            return $this->get_file_instance($filerecord);
        } else {
            return false;
        }
    }
933042
public function handle($path, $width, $height, $action)
    {
        $file = $this->filesystem->getFile($path);

        return $this->urlGenerator->generate(
            'thumb',
            [
                'width'  => $width,
                'height' => $height,
                'action' => $action[0], // first char
                'file'   => $file->getPath(),
            ]
        );
    }
39973
public function processCrop($size, $upload_path, $file, $sizeMeta) {
		$upload_info = wp_upload_dir();
		$subdir = trim(str_replace($upload_info['basedir'], '', $upload_path), '/');
		$upload_path = rtrim(str_replace($subdir, '', $upload_path), '/');

		if($this->client && $this->client->enabled()) {
			$sizeMeta = $this->processFile($upload_path, $subdir.'/'.$file, $sizeMeta);
		}

		return $sizeMeta;
	}
287739
public static void blur(int[] in, int[] out, int width, int height, float radius) {
		int widthMinus1 = width - 1;
		int r = (int) radius;
		int tableSize = 2 * r + 1;
		int divide[] = new int[256 * tableSize];

		for (int i = 0; i < 256 * tableSize; i++) {
			divide[i] = i / tableSize;
		}

		int inIndex = 0;

		for (int y = 0; y < height; y++) {
			int outIndex = y;
			int ta = 0, tr = 0, tg = 0, tb = 0;

			for (int i = -r; i <= r; i++) {
				int rgb = in[inIndex + clamp(i, 0, width - 1)];
				ta += (rgb >> 24) & 0xff;
				tr += (rgb >> 16) & 0xff;
				tg += (rgb >> 8) & 0xff;
				tb += rgb & 0xff;
			}

			for (int x = 0; x < width; x++) {
				out[outIndex] = (divide[ta] << 24) | (divide[tr] << 16) | (divide[tg] << 8) | divide[tb];

				int i1 = x + r + 1;
				if (i1 > widthMinus1) {
					i1 = widthMinus1;
				}
				int i2 = x - r;
				if (i2 < 0) {
					i2 = 0;
				}
				int rgb1 = in[inIndex + i1];
				int rgb2 = in[inIndex + i2];

				ta += ((rgb1 >> 24) & 0xff) - ((rgb2 >> 24) & 0xff);
				tr += ((rgb1 & 0xff0000) - (rgb2 & 0xff0000)) >> 16;
				tg += ((rgb1 & 0xff00) - (rgb2 & 0xff00)) >> 8;
				tb += (rgb1 & 0xff) - (rgb2 & 0xff);
				outIndex += height;
			}
			inIndex += width;
		}
	}
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;
	}
1142308
public static function saveImage($table_name, $field_name, $file_name, $row_id=null, $extension=null) {
		//get field info
		$table 	= config('center.tables.' . $table_name);
		$field = $table->fields->{$field_name};
		$unique	= Str::random(5);

		//make path
		$path = implode('/', [
			config('center.files.path'),
			$table->name,
			$unique,
		]);

		//also make path in the filesystem
		mkdir(public_path() . $path, 0777, true);

		//get name and extension
		$name		= substr($field->name, 0, -3);
		$file		= file_get_contents($file_name);
		if (!$extension) $extension = pathinfo($file_name, PATHINFO_EXTENSION);
		$url		= $path . '/' . $name . '.' . $extension;

		//process and save image
		if (!empty($field->width) && !empty($field->height)) {
			Image::make($file)
				->fit((int)$field->width, (int)$field->height)
				->save(public_path() . $url);
		} elseif (!empty($field->width)) {
			Image::make($file)
				->widen((int)$field->width)
				->save(public_path() . $url);
		} elseif (!empty($field->height)) {
			Image::make($file)
				->heighten(null, (int)$field->height)
				->save(public_path() . $url);
		} else {
			Image::make($file)
				->save(public_path() . $url);
		}

		//try to delete file
		@unlink($file_name);
		
		//try to delete previous value(s)
		if ($row_id) {
			$previous_images = DB::table(config('center.db.files'))
				->where('table', $table->name)
				->where('field', $field->name)
				->where('row_id', $row_id);
			foreach ($previous_images as $previous_image) {
				@unlink($previous_image->url);
			}
		}

		//get dimensions
		list($width, $height, $type, $attr) = getimagesize(public_path() . $url);

		//get size
		$size = filesize(public_path() . $url);

		//insert record for image
		$file_id = DB::table(config('center.db.files'))->insertGetId([
			'table' =>			$table->name,
			'field' =>			$field->name,
			'url' =>			$url,
			'width' =>			$width,
			'row_id' => 		$row_id,
			'height' =>			$height,
			'size' =>			$size,
			'created_at' =>		new DateTime,
			'created_by' =>		Auth::guest() ? null : Auth::user()->id,
			'precedence' =>		DB::table(config('center.db.files'))
				->where('table', $table->name)
				->where('field', $field->name)
				->max('precedence') + 1,
		]);

		//come up with adjusted display size based on user-defined maxima
		list($screenwidth, $screenheight) = self::getImageDimensions($width, $height);
		
		//return array
		return [
			'file_id' =>		$file_id, 
			'url' =>			$url,
			'width' =>			$width,
			'height' =>			$height,
			'screenwidth' =>	$screenwidth,
			'screenheight' =>	$screenheight,
		];
	}
796673
public function actionCrop($file_id, $x, $y, $w, $h)
    {
        if(Yii::$app->request->isAjax)
        {
            // find file by Id
            $oneFile = OneFile::findOne($file_id);
            // load model for path to file and image sizes
            $modelName = $oneFile->model;
            $model = $modelName::findOne($oneFile->parent_id);
            
            $path = $model->getFilePath($oneFile->subdir, '', true);
            $file = $oneFile->name;
            // load original image
            $image = new SimpleImage($path . 'original/' . $file);
            // crop
            $image->crop($w, $h, $x, $y);
            // choice images with type main or with param crop = true
            $sizes = [];
            foreach($model->sizes as $type => $params) {
                if($type == 'main' || (isset($params['crop']) && $params['crop']))
                    $sizes[$type] = $params;
            }
            // resize & save
            $image->resizeSave($path, $file, $sizes);

            // return the image and it's id that you just added
            echo json_encode(['files' => [[
                "name" => $oneFile->original, 
                "url" => $model->getImageByName($oneFile->name, $oneFile->subdir, ''), 
                "thumbnailUrl" => $model->getImageByName($oneFile->name, $oneFile->subdir, 'thumb'), 
                'id' => $oneFile->id,
            ]]]);
        }
    }
479769
static function createImage( $width, $height, &$useTruecolor )
    {
        if ( $useTruecolor === null )
        {
//             print( "has GD2='" . eZImageInterface::hasGD2() . "'<br/>" );
            $useTruecolor = eZImageInterface::hasGD2();
        }
        if ( $useTruecolor and
             !function_exists( 'ImageCreateTrueColor' ) )
        {
            eZDebug::writeWarning( 'Function ImageCreateTrueColor does not exist, cannot create true color images', __METHOD__ );
            $useTruecolor = false;
        }
        if ( $useTruecolor )
            $imageObject = ImageCreateTrueColor( $width, $height );
        else
            $imageObject = ImageCreate( $width, $height );
        return $imageObject;
    }
461540
public function imageUrl($width, $height, $fit): string
    {
        // Sign the URL, to protect against mass-resize attacks.
        $glide_key = Site::getPreference('glide-key');
        if (empty($glide_key)) {
            $glide_key = bin2hex(random_bytes(128));
            Site::setPreference('glide-key', $glide_key);
        }

        if (Auth::accessLevel($this->media->tree()) > $this->media->tree()->getPreference('SHOW_NO_WATERMARK')) {
            $mark = 'watermark.png';
        } else {
            $mark = '';
        }

        $url_builder = UrlBuilderFactory::create(WT_BASE_URL, $glide_key);

        $url = $url_builder->getUrl('index.php', [
            'route'     => 'media-thumbnail',
            'xref'      => $this->media->xref(),
            'ged'       => $this->media->tree()->name(),
            'fact_id'   => $this->fact_id,
            'w'         => $width,
            'h'         => $height,
            'fit'       => $fit,
            'mark'      => $mark,
            'markh'     => '100h',
            'markw'     => '100w',
            'markalpha' => 25,
            'or'        => 0,
            // Intervention uses exif_read_data() which is very buggy.
        ]);

        return $url;
    }
1181443
public static function blob2file($file_id)
    {
        global $CFG, $PDOX;

        if ( !isset($CFG->dataroot) || strlen($CFG->dataroot) < 1 ) return;

        $stmt = $PDOX->prepare("SELECT file_sha256, blob_id
            FROM {$CFG->dbprefix}blob_file
            WHERE path IS NULL AND file_id = :ID");
        $stmt->execute(array(':ID' => $file_id));

        $row = $stmt->fetch(\PDO::FETCH_ASSOC);
        if ( ! $row ) return false;

        $blob_id = $row['blob_id'];
        $file_sha256 = $row['file_sha256'];
        $blob_folder = BlobUtil::mkdirSha256($file_sha256);
        if ( ! $blob_folder ) {
            return "Error: migrate=$file_id folder failed sha=$file_sha256";
        }
        $blob_name =  $blob_folder . '/' . $file_sha256;

        $lob = false;
        if ( ! $blob_id ) {
            // Cope gracefully when there is no content column in blob_file
            try {
                $lstmt = $PDOX->prepare("SELECT content FROM {$CFG->dbprefix}blob_file WHERE file_id = :ID");
                $lstmt->execute(array(":ID" => $file_id));
                $lstmt->bindColumn(1, $lob, \PDO::PARAM_LOB);
                $lstmt->fetch(\PDO::FETCH_BOUND);
            } catch (\Exception $e) {
                return "Error: No content to migrate for legacy blob file_id=$file_id";
            }
        } else {
            $lstmt = $PDOX->prepare("SELECT content FROM {$CFG->dbprefix}blob_blob WHERE blob_id = :ID");
            $lstmt->execute(array(":ID" => $blob_id));
            $lstmt->bindColumn(1, $lob, \PDO::PARAM_LOB);
            $lstmt->fetch(\PDO::FETCH_BOUND);
        }

        if ( ! is_string($lob) ) {
            return "Error: LOB is not a string. fi=$file_id bi=$blob_id";
        }

        $retval = file_put_contents($blob_name, $lob);
        if ( $retval != strlen($lob) ) {
            return "Error: Failed to write fi=$file_id (".strlen($lob).") to $blob_name";
        }
        error_log("Migrated fi=$file_id (".strlen($lob).") to $blob_name");
        $lstmt = $PDOX->prepare("UPDATE {$CFG->dbprefix}blob_file
            SET path=:PATH, blob_id=NULL WHERE file_id = :ID");
        $lstmt->execute(array(
            ":ID" => $file_id,
            ":PATH" => $blob_name
        ));

        // Make sure to handle the fact that content might not be there...
        try {
            $lstmt = $PDOX->prepare("UPDATE {$CFG->dbprefix}blob_file
                SET content=NULL WHERE file_id = :ID");
            $lstmt->execute(array( ":ID" => $file_id));
        } catch (\Exception $e ) {
            // No problem - the column won't be there...
        }
        return true;
    }
165451
protected function getStoredThumbnailPath($file_id, $version_id, $storage_location_id, $thumbnail_handle, $format)
    {
        $builder = $this->connection->createQueryBuilder();
        $query = $builder
            ->select('path')->from('FileImageThumbnailPaths', 'p')
            ->where('p.fileID = :file')
            ->andWhere('p.fileVersionID = :version')
            ->andWhere('p.storageLocationID = :storage')
            ->andWhere('p.thumbnailTypeHandle = :thumbnail')
            ->andWhere('p.thumbnailFormat = :format')
            ->setParameters(array(
                'file' => $file_id,
                'version' => $version_id,
                'storage' => $storage_location_id,
                'thumbnail' => $thumbnail_handle,
                'format' => $format,
            ))->execute();

        if ($query->rowCount()) {
            return $query->fetchColumn();
        }

        return null;
    }
1288151
public function thumbnailElement($file_id)
    {
        /** @var LazaretFile $lazaretFile */
        $lazaretFile = $this->getLazaretFileRepository()->find($file_id);

        if (null === $lazaretFile) {
            return new Response(null, 404);
        }

        $lazaretThumbFileName = $this->app['tmp.lazaret.path'].'/'.$lazaretFile->getThumbFilename();

        return $this->deliverFile(
            $lazaretThumbFileName,
            $lazaretFile->getOriginalName(),
            DeliverDataInterface::DISPOSITION_INLINE,
            'image/jpeg'
        );
    }