gpt4 book ai didi

php - imagepng 非常慢

转载 作者:可可西里 更新时间:2023-11-01 00:48:45 27 4
gpt4 key购买 nike

我有一个 .php 文件,该文件应该加载要在 img 标签中显示的图像
(即 <img src="the_file.php?which=0"/> )。它看起来像这样:

<?php
ob_clean();

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

include_once("util.php");

//Do a simple calculation to get $name from (int)$_GET["which"];

$im = imagecreatefrompng("protected_directory/".$name.".png");

imagepng($im,NULL,0,NULL);

imagedestroy($im);

ob_end_flush();
?>

它工作正常,但图像加载比直接加载要慢得多
(即 <img src="protected_directory/the_name.png"/> ,其中“the_name”的计算方式与 PHP 文件中的计算方式相同,但我不能这样做这是因为 protected_directory 不是世界可读的)。

我的问题是,为什么突然变慢了?这不是一个大图像,但也不是非常小。

最佳答案

如果您只是显示现有文件,请使用 readfile() 将其输出到浏览器。无需为此创建可编辑的 GD 对象的所有开销。

关于php - imagepng 非常慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11911162/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com