可以加快 php/imagick 中的圖像加載速度 (Possible to speed up image loading in php/imagick)


問題描述

可以加快 php/imagick 中的圖像加載速度 (Possible to speed up image loading in php/imagick)

我注意到在 php 中將圖像加載到 imagick ($im = new Imagick($sFilename);) 對於 8MB 圖像需要 0.6 秒。這對我來說似乎有點慢,所以我嘗試了一個測試並使用 file_get_contents 讀取文件。大約 0.005 秒。更好的。有點太好了,我猜那裡有一些緩存?

但是我可以將同一個文件加載到 imagick 中十幾次,它總是 ~0.6 秒。

我可以告訴 file_get_contents 以某種方式繞過系統緩存,讓我更好地了解從我的硬盤驅動器中檢索 8MB 文件的原始速度?

有什麼可以加快 imagick 的嗎? ? 或者這個操作0.6秒是完全正常的嗎?


參考解法

方法 1:

Is there anything that can be done to speed up imagick?

Buy a faster CPU

Or is 0.6 seconds for this operation completely normal?

Yes.

This seems a bit slow to me

but it seems a long time for that.

I guess there's some caching going on there?

You're just guessing that something should be faster.....and you'r comparing it to a completely different operation. file_get_contents just reads the bytes in the file off the disk. Creating an image from a JPG means the computer has to read the bytes off the disk, and then decode them from the compressed data to be the actual image data.

If you want to see how much work has to be done during the compression, you can easily see this by writing the image out in an uncompressed format e.g.

$imagick = new Imagick("./testImage.jpg");
$imagick‑>setImageFormat('BMP');
$imagick‑>writeImage("./output.bmp");

And yes, this is longer than is reasonable for a HTTP request to take processing. Which is just another reason for why not running Imagick in a webserver is a good idea, but to instead run it as a background task.

(by CodemonkeyDanack)

參考文件

  1. Possible to speed up image loading in php/imagick (CC BY‑SA 2.5/3.0/4.0)

#imagick #imagemagick #PHP






相關問題

Imagick 安裝錯誤 - 類未定義 (Imagick Installation Errors - Class Undefined)

GD/Imagick 不保存我的圖像 (GD/Imagick doesn't save my image)

Imagick 使用不同的目錄和數據庫 PDF 來縮略圖 JPG (Imagick using different directory and database PDF to thumbnail JPG)

如何在不損失分辨率和質量的情況下減小圖像尺寸(高度、寬度) (How to decrease image size(height, width) without losing its resolution and quality)

Đang cố gắng để tưởng tượng chạy trên PHP 5.4.3 ở Windows x64 (Trying to get imagick running on PHP 5.4.3 at Windows x64)

WampServer 和 Imagemagick,無法識別 imagick php 模塊 (WampServer and Imagemagick, imagick php module not recogized)

PHP Imagick:如何將自定義圖像屬性保存到文件 (PHP Imagick: How to save custom image property to file)

PHP Imagick - 顯示多圖像 TIFF 的第一片 (PHP Imagick - display first slice of mutli image TIFF)

可以加快 php/imagick 中的圖像加載速度 (Possible to speed up image loading in php/imagick)

PHP imagick 相當於 -define png:color-type=6 (PHP imagick equivalent of -define png:color-type=6)

php Imagick::levelImage 使用 (php Imagick::levelImage usage)

imagick:無法查詢字體度量 (Imagick: Failed to query the font metrics)







留言討論