Jump to content

imagecopyresampled() problem..


jonstu

Recommended Posts

hey people,

 

I am running a image uploading script on my domain. It seems to do the job fine in firefox and opera browsers BUT in the internet explorer, it gives me this error.

 

imagecopyresampled(): the given argument is not a valid image resource.

 

My question why MS IE is not letting my script run successfully while other browsers seem to let it work fine.  I have been looking for help all around and it seems this forum might rescue me. please help. why is it not working in IE only?

Link to comment
https://forums.phpfreaks.com/topic/41506-imagecopyresampled-problem/
Share on other sites

here is the simple code:

 

 

$resized = imagecreatetruecolor(450, 450);

if($HTTP_POST_FILES['userfile']['type'] == 'image/png')

                    $original = imagecreatefrompng($HTTP_POST_FILES['userfile']['tmp_name']);

if($HTTP_POST_FILES['userfile']['type'] == 'image/jpg' || $HTTP_POST_FILES['userfile']['type'] == 'image/jpeg')

                    $original = imagecreatefromjpeg($HTTP_POST_FILES['userfile']['tmp_name']);

if($HTTP_POST_FILES['userfile']['type'] == 'image/gif')

                    $original = imagecreatefromgif($HTTP_POST_FILES['userfile']['tmp_name']);

if($HTTP_POST_FILES['userfile']['type'] == 'image/bmp')

                    $original = imagecreatefromwbmp($HTTP_POST_FILES['userfile']['tmp_name']);

 

imagecopyresampled($resized, $original, 0, 0, 0, 0, $nwidth, $nheight, $owidth, $oheight);

 

thanks for your reply.

 

okay,

 

I made the change as suggested but now it is showing me the error in mozilla firefox and opera (which were working fine before change). IE seems to do the resizing but makes the image quality a junk. The error is still the same but this time its other browsers and not IE. please help.

 

error:

 

imagecopyresampled(): supplied argument is not a valid Image resource on line 134

 

Warm Regards.

you guys are a life saver!

here are the changes till now that i made as u guys suggested:

 

if($HTTP_POST_FILES['userfile']['type'] == 'image/jpg' || $HTTP_POST_FILES['userfile']['type'] == 'image/pjpeg' || $HTTP_POST_FILES['userfile']['type'] == 'image/jpeg')

                    $original = imagecreatefromjpeg($HTTP_POST_FILES['userfile']['tmp_name']);

 

 

is there any problem in this....?

okay,

 

i tried replacing $HTTP_POST_FILES with $_POST but no luck. same error

 

i am worried now...

 

the code now is looking like:

 

$resized = imagecreatetruecolor(450, 450);

if($_POST['userfile']['type'] == 'image/png')

                    $original = imagecreatefrompng($_POST['userfile']['tmp_name']);

if($_POST['userfile']['type'] == 'image/jpg' || $_POST['userfile']['type'] == 'image/jpeg' || $_POST['userfile']['type'] == 'image/pjpeg')

                    $original = imagecreatefromjpeg($_POST['userfile']['tmp_name']);

if($_POST['userfile']['type'] == 'image/gif')

                    $original = imagecreatefromgif($_POST['userfile']['tmp_name']);

if($_POST['userfile']['type'] == 'image/bmp')

                    $original = imagecreatefromwbmp($_POST['userfile']['tmp_name']);

imagecopyresampled($resized, $original, 0, 0, 0, 0, $nwidth, $nheight, $owidth, $oheight);

 

please help. ???

$_POST won't do it with uploads. $HTTP_POST_FILES is deprecated, so use $_FILES.

 

if(($_FILES['userfile']['type'] == 'image/jpeg') || ($_FILES['userfile']['type'] == 'image/pjpeg') ||

        ($_FILES['userfile']['type'] == 'image/jpg'))

                        $original = imagecreatefromjpeg($_FILES['userfile']['tmp_name']);

this works in FF and IE

 

<?php
if ($_FILES['userfile']) {

    $resized = imagecreatetruecolor(450, 450);
    if($_FILES['userfile']['type'] == 'image/png')
                        $original = imagecreatefrompng($HTTP_POST_FILES['userfile']['tmp_name']);
    if(($_FILES['userfile']['type'] == 'image/jpeg') || ($_FILES['userfile']['type'] == 'image/pjpeg') || 
        ($_FILES['userfile']['type'] == 'image/jpg'))
                        $original = imagecreatefromjpeg($_FILES['userfile']['tmp_name']);                     
    if($_FILES['userfile']['type'] == 'image/gif')
                        $original = imagecreatefromgif($_FILES['userfile']['tmp_name']);
    if($_FILES['userfile']['type'] == 'image/bmp')
                        $original = imagecreatefromwbmp($_FILES['userfile']['tmp_name']);
    list($owidth, $oheight) = getimagesize($_FILES['userfile']['tmp_name']);
    $nwidth = $nheight = 450;
    imagecopyresampled($resized, $original, 0, 0, 0, 0, $nwidth, $nheight, $owidth, $oheight);

    header("content-type: image/jpeg");
    imagejpeg($resized);
    imagedestroy($resized);
    imagedestroy($original);
}
?>
<form method='post' enctype='multipart/form-data'>
<input type='file' name='userfile'>
<input type='submit' name='action' value='Submit'>
</form>

From the list that redarrow posted it looks you need check for jpeg and pjpeg only. So my suggestion of using pjpeg was right, but I should have replaced the jpg, and not the jpeg, with pjpeg (which is why the others failed after the change.)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.