php - 图片无法在 Firefox 中加载

标签 php html css image firefox

我今天遇到了 FireFox 的问题,

当我想在 Chrome 上上传图像(并用 php 调整它的大小)时,它工作正常,然后显示图像。当我在 FireFox 上尝试相同的操作时,它不会随后加载图像。

这是加载错误的示例图片:

enter image description here

更新:

我调用这个 ImageProcessor 类

$ImageProcessor = new ImageProcessor();
$ImageProcessor->Load("/home/admin/domains/dev050.nl/public_html/web/media/uploads/".$rand.$ext);
$ImageProcessor->Resize(250, 180, RESIZE_STRETCH);
$ImageProcessor->Save("/home/admin/domains/dev050.nl/public_html/web/media/advertorials/".$rand.$ext,100);

函数:

/**
 * Resize
 *
 * @param int $width
 * @param int $height
 * @param define $mode
 * @param bool $auto_orientation houd rekening met orientatie wanneer er een resize gebeurt
 */
public function Resize($width=100, $height=100, $mode=RESIZE_STRETCH, $auto_orientation=false){

    // Validate resize mode
    $valid_modes = array("stretch", "fit", "crop");
    if(in_array($mode, $valid_modes)){
        $this->_resize_mode = $mode;
    }else{
        $this->showError("The resize mode '" . $mode . "' does not exists.");
    }

    // Aspect ratio resize based on width
    if(is_numeric($width) && !is_numeric($height)){
        $ratio = $this->_old_width / $width;
        $height = ceil($this->_old_height / $ratio);
    }

    // Aspect ratio resize based on height
    if(is_numeric($height) && !is_numeric($width)){
        $ratio = $this->_old_height / $height;
        $width = ceil($this->_old_width / $ratio);
    }

    // Mode calculations
    switch($mode){
        case "stretch":
            $dst_x = 0;
            $dst_y = 0;
            $src_x = 0;
            $src_y = 0;
            $dst_w = $width;
            $dst_h = $height;
            $src_w = $this->_old_width;
            $src_h = $this->_old_height;
            break;
        case "fit":
            $dst_x = 0;
            $dst_y = 0;
            $src_x = 0;
            $src_y = 0;
            $dst_w = ($this->_old_width > $this->_old_height) ? $this->_old_width : $width;
            $dst_h = ($this->_old_height > $this->_old_width) ? $this->_old_height : $height;
            $src_w = $this->_old_width;
            $src_h = $this->_old_height;
            if($dst_w == $this->_old_width){
                $ratio = $dst_h/$this->_old_height;
                $dst_w = floor($dst_w * $ratio);
            }
            if($dst_h == $this->_old_height){
                $ratio = $dst_w/$this->_old_width;
                $dst_h = floor($dst_h * $ratio);
            }

            $width = $width > $dst_w ? $dst_w : $width;
            $height = $height > $dst_h ? $dst_h : $height;
            break;
        case "crop":
            $width = $width > $this->_old_width ? $this->_old_width : $width;
            $height = $height > $this->_old_height ? $this->_old_height : $height;
            $dst_x = 0;
            $dst_y = 0;
            $calc_x = ceil($this->_old_width/2) - floor($width / 2);
            $src_x = $calc_x > 0 ? $calc_x : 0;
            $calc_y = ceil($this->_old_height/2) - floor($height / 2);
            $src_y = $calc_y > 0 ? $calc_y : 0;
            $dst_w = $this->_old_width;
            $dst_h = $this->_old_height;
            $src_w = $this->_old_width;
            $src_h = $this->_old_height;
            break;
    }

    // Set news size vars because these are used for the
    // cache name generation
    $this->_new_width = $width;
    $this->_new_height = $height;

    $this->_old_width = $width;
    $this->_old_height = $height;

    // Lazy load for the directurl cache to work
    $this->lazyLoad();
    if($this->_cache_skip) return true;

    // Create canvas for the new image
    $new_image = imagecreatetruecolor($width, $height);

     // Check if this image is PNG or GIF to preserve its transparency
    if(($this->_image_type == 1) || ($this->_image_type == 3))
    {
        imagealphablending($new_image, false);
        imagesavealpha($new_image,true);
        $transparent = imagecolorallocatealpha($new_image, 255, 255, 255, 127);
        imagefilledrectangle($new_image, 0, 0, $width, $height, $transparent);
    }

    imagecopyresampled($new_image, $this->_image_resource, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);

    // Apply transparency to resized gif images
    if($this->_extension == "gif"){
        $trnprt_indx = imagecolortransparent($resource);
        if ($trnprt_indx >= 0) {
            $trnprt_color    = imagecolorsforindex($this->_image_resource, $trnprt_indx);
            $trnprt_indx    = imagecolorallocate($new_image, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
            imagefill($new_image, 0, 0, $trnprt_indx);
            imagecolortransparent($new_image, $trnprt_indx);
        }
    }

    $this->_image_resource = $new_image;
}

最佳答案

尝试清除缓存,也许它加载但在上下文之下?

关于php - 图片无法在 Firefox 中加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20373932/

相关文章:

php - Laravel 验证 : soft delete + unique email + update

php - php中抽象和接口(interface)有什么区别?

php - 如何在 laravel 5 的 DELETE 方法中传递多个参数?

html - 在放下元素时动画化 html5 拖放

java - 你可以将 html 彩色文本添加到包含共享首选项的字符串中吗?

html - 谷歌浏览器扩展覆盖!重要

css - 更改magento中的页脚内容

php - 尝试获取锁时发现哪个查询导致死锁;尝试重启交易

javascript - 将变量传递到 document.getElementById() - Javascript

javascript - jQuery动画后的图像显示问题