Jump to content

Resizing Image


andz

Recommended Posts

Is there a way to resize all images being uploaded on the server?

 

im talking about .jpg, .gif, .bmp, .png, and other image extensions

 

I have a script that converts only jpg gif and png but not sure if what's the problem of it because it only resizes 1 out of 5 images being uploaded.

 

im also using that script to create thumbnails

 

 

 

here's my function to create thumbnails and resize image

 

 

 

function scaleJPG($filename, $targetw, $targeth, $quality, $targetfilename, $crop) {

    if ($im = @imagecreatefromjpeg($filename)) {

        $w      = imagesx($im);

        $h      = imagesy($im);

        $sc    = 1;

        if ($w > $targetw){

            $sc = $targetw/$w;

        }

        if ($h > $targeth/$sc){

            $sc = $targeth/$h;

        }   

        if (!$crop){

            $result = imagecreatetruecolor($targetw, $targeth);

            $grey  = imagecolorallocate($result, 0xf1, 0xef, 0xea);

            imagefill($result, 0, 0, $grey);

            imagecopyresampled($result, $im, ($targetw - $w*$sc)/2, ($targeth - $h*$sc)/2, 0, 0, $w*$sc, $h*$sc, $w, $h);

        } else {

            $result = imagecreatetruecolor($w*$sc, $h*$sc);

            imagecopyresampled($result, $im, 0, 0, 0, 0, $w*$sc, $h*$sc, $w, $h);

        }

        imagejpeg($result, $targetfilename, $quality);

    }

}

 

 

i'm not sure if the system is exhausted to resize the imgae, most of the image size is around 3000x5000 pixels

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/159405-resizing-image/
Share on other sites

Take a look here:

http://us3.php.net/manual/en/book.image.php

Plenty more than just jpeg available

 

If that isn't enough yet there is also:

http://nl3.php.net/imagick (well on some hosts.. not all)

 

I think the problem would be with the code calling the function, or perhaps a timeout as converting a lot of images at the size is bound to lead to a timeout.

Link to comment
https://forums.phpfreaks.com/topic/159405-resizing-image/#findComment-840836
Share on other sites

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.