将透明png嵌入图像太慢

时间:2013-09-06 02:30:53

标签: 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_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

0 个答案:

没有答案