Jump to content

Resize an image multiple times?


radar

Recommended Posts

Greetings.. 

 

I have an ajax application i'm creating, that allows uploading images 1 at a time.  That part works, and it works well.  What I need to know now, is how would I go about converting the existing code I have, to change the sizing of it twice as well as renaming the images to something more website friendly.

 

here is the code that i currently have, im sure this is easy but as i can't find any workable code on the google, i am lost as to how to modify it.  so any help is appreciated.

 

<script language="JavaScript" type="text/javascript">
if(!/(\.bmp|\.gif|\.jpg|\.jpeg)$/i.test(window.parent.document.form1.filefieldname.value)) {
	window.parent.document.form1.filefieldname.value = "";
} else {
<?php
function rrmdir($dir) { 
	if (is_dir($dir)) { 
     		$objects = scandir($dir); 
     	foreach ($objects as $object) { 
       		if ($object != "." && $object != "..") { 
         		if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object); 
		} 
     	}	 
     reset($objects); 
     rmdir($dir); 
   		} 
	} 

$folder = isset($_POST['folder']) ? $_POST['folder'] : '';
if($folder == '') {
	$rand = rand(5, 1000000);
	$folder = 'temp'.$rand;
	?>
	window.parent.document.form1.folder.value = "<?php echo $folder; ?>";
	<?php
}
if(!is_dir("../uploads/".$folder)) {
	mkdir('../uploads/'.$folder);
} else {
	$rand = rand(5, 100000);
	$folder = $folder.''.$rand;
	mkdir('../uploads/'.$folder);
}
$image_name = $_FILES["filefieldname"]["name"];
$newname = "../uploads/".$folder."/".$image_name;
move_uploaded_file($_FILES["filefieldname"]["tmp_name"], $newname);
?>
var parDoc = window.parent.document;
var A = window.parent.document.form1.upload_cnt.value;
A = Number(A);
B = 1;
var cnt = A + B;
if(cnt == '8') {
window.parent.document.form1.filefieldname.disabled=true;
}
parDoc.getElementById('upload_cnt').value = cnt;
parDoc.getElementById('files_list').innerHTML += '<br><a href="../uploads/<?php echo $folder.'/'.$_FILES['filefieldname']['name'] ?>"><?php echo $_FILES['filefieldname']['name'] 		
?></a>';
window.parent.document.form1.filefieldname.value="";
}
</script>

Link to comment
https://forums.phpfreaks.com/topic/210005-resize-an-image-multiple-times/
Share on other sites

Just checking in, anyone know how to do this today?  I posted the entire code, though really the only part that will matter is:

 

$image_name = $_FILES["filefieldname"]["name"];	
$newname = "../uploads/".$folder."/".$image_name;	
move_uploaded_file($_FILES["filefieldname"]["tmp_name"], $newname);

 

how to change that so that it changes the width to a certain number, and will auto adjust the height to the neighboring height ('constrain proportions').  I've never had to do it, don't know how.  and yeah.  If i can get the code for doing it one time, i should be able to theoretically copy the same code to do it a 2nd time?

Okay so based on that code, i would change mine effectively to something like...

 

$prod_img = "../uploads/".$folder."/".$image_name;

$srcimg = ImageCreateFromJPEG($prod_img) or die('Problem In opening Source Image'); // does this work for .bmp, .gif, .jpg, .png as well? because i'm allowing the use of all of those through this script.

$width = '432';
$sizes = getimagesize($_FILES["filefieldname"]);
$aspect_ratio = $sizes[1]/$sizes[0];

$new_height = abs($width/$aspect_ratio);

createImage($width, $new_height, $srcimg, $prod_img_thumb[$cur_img]);

I dont know i havent run it...  im actually working on a different part of the site atm..  this part is just an afterthought of the uploading feature in the administration panel.

 

so figured i would figure out how to do it, and save that info to add it in next week.

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.