图片无法在Firefox中加载

时间:2022-11-14 12:03:42

I have a problem with FireFox today,

我今天遇到FireFox的问题,

When I want to upload an image (and resize it with php) on Chrome it works all fine, and shows the image afterwards. When I try the same on FireFox, it won't load the image afterwards.

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

This is an example image with the loading error:

这是一个带有加载错误的示例图像:

图片无法在Firefox中加载

UPDATE :

更新:

I call this ImageProcessor class

我称之为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);

The function:

功能:

/**
 * 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 个解决方案

#1


0  

Try clearing cache, maybe it loads but underneath the context?

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

#1


0  

Try clearing cache, maybe it loads but underneath the context?

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