ayok Posted August 19, 2007 Share Posted August 19, 2007 Hi guys, I have this script to resize the image <?php function change_pic($pic_name) { header("Content-type:image/jpeg"); $im_src = imagecreatefromjpeg($pic_name); $width_src = imagesx($im_src); $height_src = imagesy($im_src); $width_dst = 100; $height_dst = 100; $quality = 60; //resize process $im = imagecreatetruecolor($width_dst, $height_dst); imagecopyresampled($im, $im_src, 0, 0, 0, 0, $width_dst, $height_dst, $width_src, $height_src); imagejpeg($im, $pic_name, $quality); imagedestroy($im_src); imagedestroy($im); } if ($fupload_type = "image/pjpeg" || $fupload_type = "image/jpeg") { copy($fupload, "./$fupload_name"); change_pic($fupload_name); } else { echo "File must be JPEG"; }?> The codes resize the uploaded pic to 100X100 px from the original pic. However, I want to modify this script so I can resize into two size and put it in different folder. I can put the original pic with the original size in a folder, but how can I have two resized pic like, say, 100X100 and 300X300? Thank you, ayok Quote Link to comment https://forums.phpfreaks.com/topic/65668-image-upload/ Share on other sites More sharing options...
phpknight Posted August 19, 2007 Share Posted August 19, 2007 Save the original to a folder. Open, resize it, save that somewhere. Close it. Repeat the process for your other size. In fact, you might be able to resize it twice without even closing it. Where are you getting stuck? Quote Link to comment https://forums.phpfreaks.com/topic/65668-image-upload/#findComment-328052 Share on other sites More sharing options...
ayok Posted August 20, 2007 Author Share Posted August 20, 2007 Thank you phpknight, I've tried your advice to save the original folder first, and open it to resize it. But I don't know how to open and resize the saved files. Could you tell me how? Thanks, ayok Quote Link to comment https://forums.phpfreaks.com/topic/65668-image-upload/#findComment-328654 Share on other sites More sharing options...
MadTechie Posted August 20, 2007 Share Posted August 20, 2007 try this <?php function change_pic($pic_name, $newname, $width=100, $height=100, $quality=60) { //not sure why the head as we're saving to file! //header("Content-type:image/jpeg"); $im_src = imagecreatefromjpeg($pic_name); $width_src = imagesx($im_src); $height_src = imagesy($im_src); $width_dst = $width; $height_dst = $height; $quality = $quality; //resize process $im = imagecreatetruecolor($width_dst, $height_dst); imagecopyresampled($im, $im_src, 0, 0, 0, 0, $width_dst, $height_dst, $width_src, $height_src); imagejpeg($im, $newname, $quality); imagedestroy($im_src); imagedestroy($im); } if ($fupload_type = "image/pjpeg" || $fupload_type = "image/jpeg") { copy($fupload, "./$fupload_name"); change_pic($fupload_name, "./".$fupload_name,300,300); change_pic($fupload_name, "./100".$fupload_name,100,100); } else { echo "File must be JPEG"; }?> this code will create the 300 sized image and the 100 sized one.. Note the file name of the 100 with have 100 prefixed.. as i don't know where you wanted it stored Quote Link to comment https://forums.phpfreaks.com/topic/65668-image-upload/#findComment-328657 Share on other sites More sharing options...
ayok Posted August 20, 2007 Author Share Posted August 20, 2007 Thanks MadTechie, I'll try this. not sure why the head as we're saving to file! is the header unnecesarry? Quote Link to comment https://forums.phpfreaks.com/topic/65668-image-upload/#findComment-328707 Share on other sites More sharing options...
MadTechie Posted August 20, 2007 Share Posted August 20, 2007 Nope, the header would be needed IF you have the php as the image but your send the image resource to the file not the screen Quote Link to comment https://forums.phpfreaks.com/topic/65668-image-upload/#findComment-328799 Share on other sites More sharing options...
ayok Posted August 20, 2007 Author Share Posted August 20, 2007 I see.. Thanks MadTechie, it works now. However, I still have a question regarding uploading image. The script is working on localhost with IE. It uploads and resizes the picture, but if I test on Opera, it's not uploaded. Do you know why? Thanks, ayok Quote Link to comment https://forums.phpfreaks.com/topic/65668-image-upload/#findComment-328840 Share on other sites More sharing options...
MadTechie Posted August 20, 2007 Share Posted August 20, 2007 probably the form, can you post the form for the upload and i'll take a peek Quote Link to comment https://forums.phpfreaks.com/topic/65668-image-upload/#findComment-328861 Share on other sites More sharing options...
ayok Posted August 20, 2007 Author Share Posted August 20, 2007 <?php session_start(); if(!empty($namauser) AND !empty ($passuser)) { include "../dbconnect.php"; echo "<H3 align=center>Add Picture</H3> <FORM enctype=MULTIPART/FORM-DATA METHOD=POST ACTION=input_pic.php> <table align=center border=0> <tr><td>Title: </td> <td><INPUT TYPE=TEXT SIZE=60 NAME= title></td></tr> <tr><td>Category: </td> <td><SELECT NAME=category> <OPTION VALUE=0 SELECTED>--Choose Category--"; $tampil=mysql_query("SELECT * FROM category ORDER BY id"); while($data=mysql_fetch_array($tampil)) { echo "<OPTION VALUE=$data[id]>$data[name]"; } echo "</OPTION></SELECT></td></tr> <tr><td>Upload:</td> <td> <input type=file name=fupload></td></tr> </table> <INPUT TYPE=SUBMIT VALUE=Add> </FORM><a href=foto2.php>Show and delete pictures</a><BR> <a href=logout.php>logout</a>"; }else{ echo "You have to login before adding new items<BR>"; echo "<a href=form_login.php>Login</a>"; } ?> <style type="text/css"> <!-- body,td,th { font-family: Arial, Helvetica, sans-serif; font-size: 10px; color: #FFFFFF; } body { background-color: #993300; } a { font-family: Arial, Helvetica, sans-serif; font-size: 10px; color: #00FF00; font-weight: bold; } a:link { text-decoration: none; } a:visited { text-decoration: none; color: #FFFF00; } a:hover { text-decoration: underline; color: #FFFFFF; } a:active { text-decoration: none; } --> </style> Quote Link to comment https://forums.phpfreaks.com/topic/65668-image-upload/#findComment-328920 Share on other sites More sharing options...
MadTechie Posted August 20, 2007 Share Posted August 20, 2007 ok you need to add some quotes i think thats all of them! <?php session_start(); if(!empty($namauser) AND !empty ($passuser)) { include "../dbconnect.php"; echo "<H3 align=center>Add Picture</H3> <FORM enctype='MULTIPART/FORM-DATA' METHOD='POST' ACTION='input_pic.php'> <table align=center border=0> <tr><td>Title: </td> <td><INPUT TYPE='TEXT' SIZE=60 NAME='title'></td></tr> <tr><td>Category: </td> <td><SELECT NAME='category'> <OPTION VALUE='0' SELECTED>--Choose Category--"; $tampil=mysql_query("SELECT * FROM category ORDER BY id"); while($data=mysql_fetch_array($tampil)) { echo "<OPTION VALUE='$data[id]'>$data[name]"; } echo "</OPTION></SELECT></td></tr> <tr><td>Upload:</td> <td> <input type='file' name='fupload'></td></tr> </table> <INPUT TYPE='SUBMIT' VALUE='Add'> </FORM><a href='foto2.php'>Show and delete pictures</a><BR> <a href='logout.php'>logout</a>"; }else{ echo "You have to login before adding new items<BR>"; echo "<a href='form_login.php'>Login</a>"; } ?> <style type="text/css"> <!-- body,td,th { font-family: Arial, Helvetica, sans-serif; font-size: 10px; color: #FFFFFF; } body { background-color: #993300; } a { font-family: Arial, Helvetica, sans-serif; font-size: 10px; color: #00FF00; font-weight: bold; } a:link { text-decoration: none; } a:visited { text-decoration: none; color: #FFFF00; } a:hover { text-decoration: underline; color: #FFFFFF; } a:active { text-decoration: none; } --> </styl Quote Link to comment https://forums.phpfreaks.com/topic/65668-image-upload/#findComment-328933 Share on other sites More sharing options...
ayok Posted August 20, 2007 Author Share Posted August 20, 2007 the script works fine in localhost, but when I tried in my webserver, i got this error: "Allowed memory size of 8388608 bytes exhausted (tried to allocate 6400 bytes) " Why is that? thanks, ayok Quote Link to comment https://forums.phpfreaks.com/topic/65668-image-upload/#findComment-329291 Share on other sites More sharing options...
MadTechie Posted August 20, 2007 Share Posted August 20, 2007 Oh boy.. thats due to the server setup.. try to override it change $im_src = imagecreatefromjpeg($pic_name); to set_time_limit ( 0 ); //reset timeout timer ini_set('memory_limit', '30M'); $im_src = imagecreatefromjpeg($pic_name); let hope you don't join GaryDT's thread Quote Link to comment https://forums.phpfreaks.com/topic/65668-image-upload/#findComment-329299 Share on other sites More sharing options...
ayok Posted August 20, 2007 Author Share Posted August 20, 2007 Wow.. it works.. you're just great. Thank you very much! Cheers, ayok Quote Link to comment https://forums.phpfreaks.com/topic/65668-image-upload/#findComment-329316 Share on other sites More sharing options...
MadTechie Posted August 20, 2007 Share Posted August 20, 2007 Cool, can you please click topic solved bottom left i'm glade it up and running Quote Link to comment https://forums.phpfreaks.com/topic/65668-image-upload/#findComment-329320 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.