0

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

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
4

0 回答 0