Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.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 调整GD生成的图像大小,但失败_Php_Gd - Fatal编程技术网

Php 调整GD生成的图像大小,但失败

Php 调整GD生成的图像大小,但失败,php,gd,Php,Gd,我有这个代码,它会在屏幕上生成条形码。但它太小,无法打印。因此,我想缩放大小,但为什么$thumb图像不显示在屏幕上?仅显示$image(原始图像)。我错过了什么?多谢各位 <?php //-- bunch of codes here -- //-- then generate image -- // Draw barcode to the screen header ('Content-type: image/png'); imagepng($

我有这个代码,它会在屏幕上生成条形码。但它太小,无法打印。因此,我想缩放大小,但为什么
$thumb
图像不显示在屏幕上?仅显示$image(原始图像)。我错过了什么?多谢各位

<?php
    //-- bunch of codes here --
    //-- then generate image -- 

    // Draw barcode to the screen
    header ('Content-type: image/png');
    imagepng($image);
    imagedestroy($image);

    // Then resize it
    // Get new sizes
    list($width, $height) = getimagesize($image);
    $newwidth = $width * 2;
    $newheight = $height * 2;

    // Resize
    imagecopyresized($thumb, $image, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

    // Output and free memory
    header ('Content-type: image/png');
    imagepng($thumb);
    imagedestroy($thumb);
?>

虽然没有所有的代码来处理我的模拟部件,但最终的结果是新图像的大小是原始图像的两倍。主要的事情不是最初发送头,而是将生成的图像保存到临时文件中,然后处理该文件

<?php
    //-- bunch of codes here --
    //-- then generate image -- 


    /* You will already have a resource $image, this emulates that $image so you do not need this line */
    $image=imagecreatefrompng( 'c:/wwwroot/images/maintenance.png' );



    /* define name for temp file */
    $tmpimgpath=tempnam( sys_get_temp_dir(), 'img' );

    /* do not send headers here but save as a temp file */
    imagepng( $image, $tmpimgpath );


    // Then resize it, Get new sizes ( using the temp file )
    list( $width, $height ) = getimagesize( $tmpimgpath );
    $newwidth = $width * 2;
    $newheight = $height * 2;

    /* If $thumb is defined outwith the code you posted then you do not need this line either  */
    $thumb=imagecreatetruecolor( $newwidth, $newheight );

    // Resize
    imagecopyresized( $thumb, $image, 0, 0, 0, 0, $newwidth, $newheight, $width, $height );

    // Output and free memory
    header ('Content-type: image/png');
    @imagedestroy( $image );
    @imagepng( $thumb );
    @imagedestroy( $thumb );
    @unlink( $tmpimgpath );
?>

虽然没有所有的代码来处理我的模拟部件,但最终的结果是新图像的大小是原始图像的两倍。主要的事情不是最初发送头,而是将生成的图像保存到临时文件中,然后处理该文件

<?php
    //-- bunch of codes here --
    //-- then generate image -- 


    /* You will already have a resource $image, this emulates that $image so you do not need this line */
    $image=imagecreatefrompng( 'c:/wwwroot/images/maintenance.png' );



    /* define name for temp file */
    $tmpimgpath=tempnam( sys_get_temp_dir(), 'img' );

    /* do not send headers here but save as a temp file */
    imagepng( $image, $tmpimgpath );


    // Then resize it, Get new sizes ( using the temp file )
    list( $width, $height ) = getimagesize( $tmpimgpath );
    $newwidth = $width * 2;
    $newheight = $height * 2;

    /* If $thumb is defined outwith the code you posted then you do not need this line either  */
    $thumb=imagecreatetruecolor( $newwidth, $newheight );

    // Resize
    imagecopyresized( $thumb, $image, 0, 0, 0, 0, $newwidth, $newheight, $width, $height );

    // Output and free memory
    header ('Content-type: image/png');
    @imagedestroy( $image );
    @imagepng( $thumb );
    @imagedestroy( $thumb );
    @unlink( $tmpimgpath );
?>


调用
imagedestroy($image)
并继续尝试获取
$image
@RamRaider:removing
imagedestroy($image)的属性
仍然不会更改结果,除了在尝试获取其高度和宽度之前销毁
$image
,您正在输出
$image
,然后输出
$thumb
。选择一个来显示,而不是在同一个文件中显示,因为这将不起作用。我不相信
getimagesize($image)
将实际获得图像的尺寸,因为此时您已将输出发送到浏览器,$image是一个资源,而不是字符串路径,$thumb最初是在哪里定义的?您调用
imagedestroy($image)
并继续尝试获取
$image
@RamRaider:removing
imagedestroy($image)的属性
仍然不会改变结果,除了在您尝试获取其高度和宽度之前销毁
$image
之外,您正在输出
$image
,然后输出
$thumb
。选择一个来显示,而不是在同一个文件中显示。我不相信
getimagesize($image)
将实际获取图像的尺寸,因为此时您已将输出发送到浏览器,$image是一个资源,而不是字符串路径,$thumb最初是在哪里定义的?