Generating Images Using gd-PHP is too slow .. Some cannot come out,

Source: Internet
Author: User
Tags imagemagick
Now we have a dynamic program to use images of different widths. Each time, the image is output based on the width and height of the image, and then {code...} is used in the html page. This is 900X400. Create a layer using the GD library of php to re-draw a picture based on the proportion {... now a dynamic program is created to use images of different width and height. Each time an image is output based on the width and height of the image

This is 900X400.

Use the GD library of php to create a layer and draw a picture based on the proportion.

imagecreatetruecolor($_n_w,$_n_h);imagecopyresampled($this->new,$this->img,0,0,$_cut_width,$_cut_height,$new_width,$new_height,$this->width,$this->height);

Finally, output the image so that html can reference this address.

header("Content-type: image/png");imagepng($imgsrc);

Now the problem is that after html is referenced, a lot of images will be half or not out, and the efficiency is too low. Is there any improvement solution?

Reply content:

Now we have a dynamic program to use images of different widths. Each time an image is output based on the width and height of the image

This is 900X400.

Use the GD library of php to create a layer and draw a picture based on the proportion.

imagecreatetruecolor($_n_w,$_n_h);imagecopyresampled($this->new,$this->img,0,0,$_cut_width,$_cut_height,$new_width,$new_height,$this->width,$this->height);

Finally, output the image so that html can reference this address.

header("Content-type: image/png");imagepng($imgsrc);

Now the problem is that after html is referenced, a lot of images will be half or not out, and the efficiency is too low. Is there any improvement solution?

Processing images in PHP consumes server resources ~~ If a page has many image resources that require such constant processing ~~ The server is busy ~~

As mentioned above ~~ The PHP program or rewrite is used to determine whether the size of the image already exists and does not exist. This can reduce the pressure on the server and increase the processing speed .~

Let's explain the meanings of those who emphasize my answers.

First, place GD and use imagick. \ ( ̄- ̄ )/

Second, memory storage.

The simplest Memory Design:

The url is cache/image0001-1024x768.jpg

If the server cannot be found, it is handed to PHP for processing. The generated result is saved. The next time it is stored, it will be different from the original data source. (○ ω '○)

Once again, in practice, there is no need to use all types of sizes during batch usage, so you can fix it by using just a few, the latter-end compaction is mainly for the convenience of the front-end, rather than the leeching)

For example, wikipedia supports arbitrary release, but generally it shows a fixed size, so there is basically no heavy computing workload. ╮ ( ̄) ╭

Use the automatic thumbnail tool of the CDN service provider. It seems that both upyun and qiniu have such interfaces.

Otherwise, use the ImageMagick library, which is twice faster than GD.

This design is wrong in itself. A more scientific design is to plan all possibilities, and then select several demarcation points to generate images of 4-5 sizes while uploading images, each time it is a pure static access
The remaining size is scaled by the browser.

Use js for control. Just search several libraries on github.
Https://github.com/search? Utf8 = % E2 % 9C % 93 & q = img + fit

Contrary to the idea on the first floor, this is not a wrong design, which is more scientific. As mentioned above, at least cache must be added.
Add a project https://github.com/thumbor/thumbor for image scaling Service

Use the imagick and ImageMagick libraries.

1. Use ImageMagick
2. Each time an image is generated, check whether the image of this size exists and does not exist... Then save (that is, cache)

We recommend that you directly use CDN vendors, such as qiniu. I use qiniu and set a set of rules to make the Resource Directory into a subdomain. Then, the image will solve the problem, no synchronization scripts are required.

Some cdn supports image thumbnails,

Or you can use rewrite to determine whether the file exists. If php does not generate the file to the same path after processing.

For example:/thumb/12345_100x100.jpgFor the first time/thumb/12345_100x100.jpg, The next time the file exists, it will be returned directly.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.