imagesx expects parameter 1 to be a resource string given

The key problem was posting sourcefile to s3 bucket I changed that to body , also I changed my php settings to allow file upload till 5 mb

Here is the solution:

$im = imagecreatetruecolor(700, 700);
$bg = imagecolorallocate ( $im, 255, 255, 255 );
imagefilledrectangle($im,0,0,700,700,$bg);



list( $width, $height , $image_type ) = getimagesize($tmp);

$max_width=700;
 $max_height= 700;

 

    # taller
    if ($height > $max_height) {
        $width = ($max_height / $height) * $width;
        $height = $max_height;
    }

    # wider
    if ($width > $max_width) {
        $height = ($max_width / $width) * $height;
        $width = $max_width;
    }


switch ($image_type)
    {
        case 1: $im3 = imagecreatefromgif($tmp); break;
        case 2: $im3 = imagecreatefromjpeg($tmp);  break;
        case 3: $im3 = imagecreatefrompng($tmp); break;
        default: return '';  break;
    }

$im2 = imagescale($im3, $width, $height);


imagecopy($im, $im2, (imagesx($im)/2)-(imagesx($im2)/2), (imagesy($im)/2)-(imagesy($im2)/2), 0, 0, imagesx($im2), imagesy($im2));



$imgdata = image_data($im);
function image_data($gdimage)
{
    ob_start();
    imagejpeg($gdimage,NULL,70);
    return(ob_get_clean());
}

And while uploading to bucket

$result = $s3->putObject([
    'Bucket' => 'yourbucket',
    'Key'    => 'filename',
    'Body' => $imgdata 
]);

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top