Download and resize PHP

I am working on a script that loads an image using PHP, and I want it to resize the image by 180 before saving it.
I tried using the WideImage library and → saveFileTO (...), but when I enable WideImage.php on the page, the page bypasses!
So here is my script, if you can help me and tell me how to do this, save the modified version

+6
php file-upload autoresize
source share
4 answers

You can use the PHP GD library to resize the image at startup.

The following code should give you an idea of ​​how to implement resizing:

// Get the image info from the photo $image_info = getimagesize($photo); $width = $new_width = $image_info[0]; $height = $new_height = $image_info[1]; $type = $image_info[2]; // Load the image switch ($type) { case IMAGETYPE_JPEG: $image = imagecreatefromjpeg($photo); break; case IMAGETYPE_GIF: $image = imagecreatefromgif($photo); break; case IMAGETYPE_PNG: $image = imagecreatefrompng($photo); break; default: die('Error loading '.$photo.' - File type '.$type.' not supported'); } // Create a new, resized image $new_width = 180; $new_height = $height / ($width / $new_width); $new_image = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // Save the new image over the top of the original photo switch ($type) { case IMAGETYPE_JPEG: imagejpeg($new_image, $photo, 100); break; case IMAGETYPE_GIF: imagegif($new_image, $photo); break; case IMAGETYPE_PNG: imagepng($new_image, $photo); break; default: die('Error saving image: '.$photo); } 
+6
source share

You can use the class that I wrote for this task:

http://code.google.com/p/image2/source/browse/#svn/trunk/includes/classes

 <?php try { $image = new Image2($path_to_image); } catch (NotAnImageException $e) { printf("FILE PROVIDED IS NOT AN IMAGE, FILE PATH: %s", $path_to_image); } $image -> resize(array("width" => 180)) -> saveToFile($new_path); // be sure to exclude the extension $new_file_location = $image -> getFileLocation(); // this will include the extension for future use 
+1
source share

You do not even need to use the WideImage library.

Check out this script here: http://bgallz.org/502/php-upload-resize-image/

You start by loading the image and saving it into a temporary image file. This script runs a form with inputs for maximum height or maximum width. Then it will create a new image file based on the new width / height, and then copy the temporary image to the new one created on the server.

You see this with the following code:

 // Create temporary image file. $tmp = imagecreatetruecolor($newwidth,$newheight); // Copy the image to one with the new width and height. imagecopyresampled($tmp,$image,0,0,0,0,$newwidth,$newheight,$width,$height); 
+1
source share

Do not use any library Check this script http://dr-wordpress.blogspot.com/2013/12/image-resizing-using-php.html Just gave the quality imges from (0-99) this code will automatically resize images when uploading

+1
source share

All Articles