Tim Kipp
Tim Kipp

Reputation: 200

PHP Image Resizing Does NOT Resize In Internet Explorer

I am having a very interesting problem. The script I wrote below works, but it doesn't work in Internet Explorer. The MAX_WIDTH variable is set to 450 and it still uploads the image with the original dimensions of the image, not 450 by whatever the conversion factor is. Any suggestions? It works and resizes in Chrome, Firefox, and Safari. Also, the version of IE I am testing on is IE 8 64-bit version. Thanks.

private function checkForResize() {
    $fileTypeArray = array('image/gif', 'image/jpeg', 'image/png');
    $origType = $this->_uploadType;
    if (in_array($origType, $fileTypeArray)) {
        $origImage = $_FILES[$this->_uploadInputField]['tmp_name'];
        $imageWidth = getimagesize($origImage);
        if ($imageWidth[0] > MAX_WIDTH) {
            // Resize here
            if ($origType == 'image/gif') {
                $imageSrc = imagecreatefromgif($origImage);
            } else if ($origType == 'image/jpeg') {
                $imageSrc = imagecreatefromjpeg($origImage);
            } else if ($origType == 'image/png') {
                $imageSrc = imagecreatefrompng($origImage);
            } else {
                return false;
            }
            $width = $imageWidth[0];
            $height = $imageWidth[1];
            $newHeight = ($height / $width) * MAX_WIDTH;
            $tmpImage = imagecreatetruecolor(MAX_WIDTH, $newHeight);
            $this->setTransparency($tmpImage, $imageSrc);
            imagecopyresampled($tmpImage, $imageSrc, 0, 0, 0, 0, MAX_WIDTH, $newHeight, $width, $height);
            imagejpeg($tmpImage, UPLOAD_DIR.DS.$this->_uploadSafeName, 100);
            imagedestroy($imageSrc);
            imagedestroy($tmpImage);
            return true;
        }
    }
    return false;
}

Upvotes: 0

Views: 316

Answers (1)

Damien Pirsy
Damien Pirsy

Reputation: 25445

Converting my comment to an answer:

The browser has nothing to do with server-side scripts going wrong, as it's on the client side.

What can be wrong, though, is the fact that MIME type is an unreliable information, for it's the browser who detects and sends the MIME type.

And IE sometimes sends an image/pjpeg or an image/x-png MIME type when dealing with jpgs or pngs, so you need to check those also when validating.

Upvotes: 3

Related Questions