Php图像调整大小和改变方向不起作用


Php image resize and change orientation doesn't work

我们正在使用这段代码来上传图像并调整它的大小,它工作了。我们添加了代码来改变图像的旋转。但是由于我们添加了代码,它不再工作了

任何想法吗?

<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
if (! function_exists('resize_image'))
{   
function resize_image($font, $desti, $x, $y){
// Primer fem resize
    $CI =& get_instance();
    $cfg['image_library'] = 'gd2';
    $cfg['source_image'] = $font;
    $cfg['new_image'] = $desti;
    $cfg['master_dim'] = "width";
    $cfg['maintain_ratio'] = TRUE;
    $cfg['width'] = $x;
    $cfg['height'] = $y;
    $CI->load->library('image_lib');
    $CI->image_lib->clear();
    $CI->image_lib->initialize($cfg);
    echo "hola9<br>";
    $CI->image_lib->resize();
    // CHANGE ORIENTATION
    $image = file_get_contents($desti);  // agafo contingut de la imatge a partir del path que conté $font
    $exif = exif_read_data($desti);
    echo "hola3<br>";
    if(!empty($exif['Orientation'])) {
        switch($exif['Orientation']) {
            case 8:
                $image = imagerotate($image,90,0);
                break;
            case 3:
                $image = imagerotate($image,180,0);
                break;
            case 6:
                $image = imagerotate($image,-90,0);
                break;
        }
    }
    // $image now contains a resource with the image oriented correctly
    /*?>
    */
    file_put_contents($desti, $image);  // poso contingut de la imatge en el path originari (path+nom.jpg)
}
}

把它放在代码的顶部:

ini_set('display_errors','On');
error_reporting(E_ALL);

这将让您知道任何错误/警告/通知。