开发者

PHP Processing on an image and display it first on page load

I'm taking an image, doing some processing on it to make it a dark blue hue, and setting it as the background image in the body of the page. The code here works exactly as expected:

 $image = imagecreatefromjpeg($backimage);
 imagefilter($image, IMG_FILTER_GRAYSCALE);
 imagefi开发者_运维知识库lter($image, IMG_FILTER_CONTRAST,40);
 imagefilter($image, IMG_FILTER_BRIGHTNESS,-80);
 imagefilter($image, IMG_FILTER_COLORIZE, 10, 0, 40);  //112, 66, 20);

The trouble is, it takes some time to process, so the full page is displayed with no background, then after a short delay, the background image appears (at least in firefox), so it looks a bit strange. I'd actually prefer it to load first, or wait until the processing is complete, then display the whole thing. Any advice? Thanks!


The trouble is, it takes some time to process

Use caching. You don't want to run these effects on the image every time it is requested. Store the results in a static JPG file (using the second parameter of imagejpeg()), and update if/when necessary.

For more detailed suggestions on how to do this (often checking the "last modified" time of the original image is the right way; sometimes, it's enough to trigger it manually) you'll have to provide more context about what you're doing and where your image is coming from.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜