stylefrogcreative Posted September 6, 2006 Share Posted September 6, 2006 Hi there,Got a deadline rapidly approaching and still banging my head against the wall - any help would be greatly appreciated!Basically I'm developing a Flash application which gives the user the option to customise an ecard with a message, company name and company logo. I've got everything working apart from the logo part.I need them to upload a logo, which is then resized and uniquely renamed, for when I pull it back in Flash.I need to specify that neither the height or the width is greater than 75 px, and resize if it is - keeping everything in scale.Here's the code so far:I generate a unique variable name and use it create a new text file ($session) $fd = fopen("$session.txt", "w");fwrite($fd, "name=$name&message=$message&contentLoaded=true");fclose($fd);I then write all the text info into this - which all works perfectly.I need to know how to let the user specify an image to upload, then once submitted I need to resize it so that neither the width nor the height is greater than 75px. We then need to save it as $session.jpg, so it has a unique name.Please help guys - I'm pulling my hair out here!Many, many thanks,Matt Link to comment https://forums.phpfreaks.com/topic/19933-image-resize-and-rename/ Share on other sites More sharing options...
zq29 Posted September 6, 2006 Share Posted September 6, 2006 This should get you on your way...[code]<?phpfunction thumbnail($image_path,$thumb_path,$image_name) { $max_width = 75; $max_height = 75; $size = getimagesize($image_path.$image_name); $width = $size[0]; $height = $size[1]; if($width != FALSE && $height != FALSE) { $x_ratio = $max_width / $width; $y_ratio = $max_height / $height; if(($width <= $max_width) && ($height <= $max_height)) { $disp_width = $width; $disp_height = $height; } elseif(($x_ratio * $height) < $max_height) { $disp_height = ceil($x_ratio * $height); $disp_width = $max_width; } else { $disp_width = ceil($y_ratio * $width); $disp_height = $max_height; } } else { return false; } $src_img = imagecreatefromjpeg($image_path.$image_name); $dst_img = imagecreatetruecolor($disp_width,$disp_height); imagecopyresized($dst_img,$src_img,0,0,0,0,$disp_width,$disp_height,imagesx($src_img),imagesy($src_img)); imagejpeg($dst_img, $thumb_path.$image_name); return true;}?>[/code] Link to comment https://forums.phpfreaks.com/topic/19933-image-resize-and-rename/#findComment-87362 Share on other sites More sharing options...
stylefrogcreative Posted September 7, 2006 Author Share Posted September 7, 2006 Wow - that's fantastic - thanks so much!With regards to renaming the image file - how would I go about saving it with a unique name? I need to name it with the vaue contained with $session, as thats how I'll call it back into Flash.Also, in the form which submits the image, how would I reference this new code, at the moment I'd be using:<form method="post" action="upload_handler.php" enctype="multipart/form-data"> <input type="file" name="logo"><br> <input type="submit" name="submit" value="Submit"> </form> Thanks again! Link to comment https://forums.phpfreaks.com/topic/19933-image-resize-and-rename/#findComment-87584 Share on other sites More sharing options...
zq29 Posted September 7, 2006 Share Posted September 7, 2006 The function I posted above would be copied into upload_handler.php and would require the image to already be uploaded:[code]<?php//We're assuming that $session already has a value, image.jpg//Copy the image from it's temp storage into our new temporary locationmove_uploaded_file($_FILES['logo']['tmp_name'],"images/logos/temp/".$session);//Resize and save the imagethumbnail("images/logos/temp","images/logos/resized/",$session);?>[/code] Link to comment https://forums.phpfreaks.com/topic/19933-image-resize-and-rename/#findComment-87586 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.