图像不会在Firefox中加载

时间:2013-12-04 11:18:52

标签: 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;
}

1 个答案:

答案 0 :(得分:0)

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