Jump to content

Resize Image


stublackett

Recommended Posts

Hi,

 

I've got an Image uploaded to a server no worries, But I've got a major problem with resizing it once it gets there

 

Ideally I'd like it to be 125px x 125 px

 

Here is my code to upload it :

 

//Set Images Upload Directory
$uploaddir = "newsimages"; 

//Handle the Image

// Upload Part
if(is_uploaded_file($_FILES['image1']['tmp_name']))
{
move_uploaded_file($_FILES['image1']['tmp_name'],$uploaddir.'/'.$_FILES['image1']['name']);
}
$img1 = $uploaddir."/".$img1;

 

But how on earth do I then get the image and resize it ???

 

I've tried an Image Class I found on Google, But it didnt seem to work

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

Just to expand

 

I've got my hands on an resizer, But it seems to not be working either

 

The original image stays the same regardless :(

 

<?php

// This is the temporary file created by PHP 
$uploadedfile = $_FILES['image1']['tmp_name'];

// Create an Image from it so we can do the resize
$src = imagecreatefromjpeg($uploadedfile);

// Capture the original size of the uploaded image
list($width,$height)=getimagesize($uploadedfile);

// For our purposes, I have resized the image to be
// 600 pixels wide, and maintain the original aspect 
// ratio. This prevents the image from being "stretched"
// or "squashed". If you prefer some max width other than
// 600, simply change the $newwidth variable
$newwidth=150;
$newheight=($height/$width)*175;
$tmp=imagecreatetruecolor($newwidth,$newheight);

// this line actually does the image resizing, copying from the original
// image into the $tmp image
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); 

// now write the resized image to disk. I have assumed that you want the
// resized, uploaded image file to reside in the ./images subdirectory.
$filename = "newsimages/". $_FILES['image1']['name'];
imagejpeg($tmp,$filename,100);

imagedestroy($src);
imagedestroy($tmp); // NOTE: PHP will clean up the temp file it created when the request
// has completed.
?>

 

Not sure on this 1

Link to comment
https://forums.phpfreaks.com/topic/116217-resize-image/#findComment-597681
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.