PHP,Image rezise为大写JPG文件抛出错误

PHP,Image rezise为大写JPG文件抛出错误,php,image,resize,Php,Image,Resize,我有一个PHP脚本,我动态调用它来实现图像 这个脚本适用于除大写JPG文件以外的所有我使用过的文件,我已经上传了这些文件并将扩展名转换为小写,但在重新调整大小后仍然会抛出错误 是否有人遇到此问题或设法解决此问题 我正在使用的脚本: <?php $source_image = $_GET["i"]; $width = $_GET["w"]; $height = $_GET["h"]; $quality = $_GET["q"]; $crop = $_GET["c"]; // If the s

我有一个PHP脚本,我动态调用它来实现图像

这个脚本适用于除大写JPG文件以外的所有我使用过的文件,我已经上传了这些文件并将扩展名转换为小写,但在重新调整大小后仍然会抛出错误

是否有人遇到此问题或设法解决此问题

我正在使用的脚本:

<?php
$source_image = $_GET["i"];
$width = $_GET["w"];
$height = $_GET["h"];
$quality = $_GET["q"];
$crop = $_GET["c"];
// If the source image isn't an image seriously we got issues
if( ! $image_data = getimagesize( $source_image ) ){
    die( "Whoa can't get the image size of the original?" );    
}
// Is it a gif, jpg or png. Sorry anything else probably not worth it.
switch( strtolower($image_data['mime']) ){
case 'image/gif':
    $get_func = 'imagecreatefromgif';
    $suffix = ".gif";
    break;
case 'image/jpeg';
    $get_func = 'imagecreatefromjpeg';
    $suffix = ".jpg";
    break;
case 'image/png':
    $get_func = 'imagecreatefrompng';
    $suffix = ".png";
    break;
}


// Setup some variables
$img_original = call_user_func( $get_func, $source_image );
$old_width = $image_data[0];
$old_height = $image_data[1];
$new_width = $width;
$new_height = $height;
$src_x = 0;
$src_y = 0;
$current_ratio = round( $old_width / $old_height, 2 );
$desired_ratio_after = round( $width / $height, 2 );
$desired_ratio_before = round( $height / $width, 2 );

// Some people don't want to upscale images. I don't care
// Uncomment if you want crash out and not upscale.

if( $old_width < $width || $old_height < $height )  {
    header('Content-Type: image/jpeg');
    imagejpeg( $img_original, NULL, $quality );
}




/**
  * If the crop option is left on, it will take an image and best fit it
  * so it will always come out the exact specified size.
  */
if( $crop )
{
/**
  * create empty image of the specified size
  */
$new_image = imagecreatetruecolor( $width, $height );

/**
  * Landscape Image
  */
if( $current_ratio > $desired_ratio_after )
{
$new_width = $old_width * $height / $old_height;
}

/**
  * Nearly square ratio image.
  */
if( $current_ratio > $desired_ratio_before && $current_ratio < $desired_ratio_after )
{
if( $old_width > $old_height )
{
$new_height = max( $width, $height );
$new_width = $old_width * $new_height / $old_height;
}
else
{
$new_height = $old_height * $width / $old_width;
}
}

/**
  * Portrait sized image
  */
if( $current_ratio < $desired_ratio_before )  {
    $new_height = $old_height * $width / $old_width;
}

    /**
      * Find out the ratio of the original photo to it's new, thumbnail-based size
      * for both the width and the height. It's used to find out where to crop.
      */
    $width_ratio = $old_width / $new_width;
    $height_ratio = $old_height / $new_height;

    /**
      * Calculate where to crop based on the center of the image
      */
    $src_x = floor( ( ( $new_width - $width ) / 2 ) * $width_ratio );
    $src_y = round( ( ( $new_height - $height ) / 2 ) * $height_ratio );
    }
    /**
      * Don't crop the image, just resize it proportionally
      */
else {
    if( $old_width > $old_height ){
        $ratio = max( $old_width, $old_height ) / max( $width, $height );
    }else{
        $ratio = max( $old_width, $old_height ) / min( $width, $height );
    }

    $new_width = $old_width / $ratio;
    $new_height = $old_height / $ratio;

    $new_image = imagecreatetruecolor( $new_width, $new_height );
}

/**
  * Where all the real magic happens
  */
imagecopyresampled( $new_image, $img_original, 0, 0, $src_x, $src_y, $new_width, $new_height, $old_width, $old_height );

/**
  * Save it as a JPG File with our $destination_filename param.
  */
header('Content-Type: image/jpeg');
imagejpeg( $new_image, NULL, $quality );

/**
  * Destroy the evidence!
  */
imagedestroy( $new_image );
imagedestroy( $img_original );

?>

我认为我遇到的问题与我用于调整大小的PHP函数有关,我使用了类似的脚本:

没有遇到任何问题,而且脚本使用GD库,因此速度更快,等等


感谢您尝试帮助Hamza。

您能在这里发布这些错误吗?这是在您查看图像时发生的,因此,当您将图像放到页面上时,您将链接到上面的脚本,定义路径和宽度等,它通常会很好地显示图像,但如果图像扩展名为大写或转换为小写,您将获得上传“此图像无法显示,它包含错误”这就是我所说的错误。@Sam删除/注释标题部分,您应该会收到错误消息,如果您注释掉标题,它只是给空白。@Sam是否检查了源(ctrl+u)?