Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将透明png嵌入图像太慢_Php_Image_Png_Watermark_Gdlib - Fatal编程技术网

Php 将透明png嵌入图像太慢

Php 将透明png嵌入图像太慢,php,image,png,watermark,gdlib,Php,Image,Png,Watermark,Gdlib,下面的函数将水印嵌入到图像上。在某些服务器上,速度非常慢,而我在服务器上从未遇到过同样的问题。有什么问题吗?我没有主意了 function add_watermark( $source_file_path, $output_file_path, $watermark_file_path, $quality = 80 ) { list( $source_width, $source_height, $source_type ) = getimagesize( $source_file_pa

下面的函数将水印嵌入到图像上。在某些服务器上,速度非常慢,而我在服务器上从未遇到过同样的问题。有什么问题吗?我没有主意了

function add_watermark( $source_file_path, $output_file_path, $watermark_file_path, $quality = 80 ) {
    list( $source_width, $source_height, $source_type ) = getimagesize( $source_file_path );

    if ( $source_type === NULL ) {
        return false;
    }

    switch ( $source_type ) {
        case IMAGETYPE_GIF:
            $source_gd_image = imagecreatefromgif( $source_file_path );
            break;
        case IMAGETYPE_JPEG:
            $source_gd_image = imagecreatefromjpeg( $source_file_path );
            break;
        case IMAGETYPE_PNG:
            $source_gd_image = imagecreatefrompng( $source_file_path );
            break;
        default:
            return false;
    }

    $overlay_gd_image = imagecreatefrompng( $watermark_file_path );
    $overlay_width = imagesx( $overlay_gd_image );
    $overlay_height = imagesy( $overlay_gd_image );

    imagecopy(
        $source_gd_image,
        $overlay_gd_image,
        $source_width - $overlay_width - 10,
        $source_height - $overlay_height - 10,
        0,
        0,
        $overlay_width,
        $overlay_height
    );

    imagejpeg( $source_gd_image, $output_file_path, $quality );
    imagedestroy( $source_gd_image );
    imagedestroy( $overlay_gd_image );
}
我不确定它是否与php.ini配置有关,但以下是所有服务器中使用的配置:

memory_limit = 100M
upload_max_filesize = 192M
post_max_size = 100M
file_uploads = On
allow_url_fopen = On

这显然取决于服务器的输入和性能。韦巴托:如果我换成ImageMagick,会有帮助吗?我怀疑GD是这里的另一个问题。我相信它会更快/更少地消耗内存,但可能是以可移植性为代价的(如果这很重要的话),因为GD或多或少是内置的。代码本身看起来不是问题。