litebearer Posted July 2, 2006 Share Posted July 2, 2006 First my apologies to the Moderators and members of this forum for this (1) not being a question, (2) not being strictly a PHP oriented post . That said, it seems (at least to me) that frequently questions are asked here regarding using PHP for imaging resizing [color=red][b]PRIOR[/b][/color] to uploading.The answer (and it is correct) inevitably is - [i][b]'You cannot do that, as PHP is server-side, therefore, the image MUST get to the server before PHP can resize/check size etc.[/b][/i]'.As a businessman/crisis-management consultant/non-programmer-programmer, my objective is to [u][i]accomplish the mission using whatever tools are efficient and readily available[/i][/u]. Ego (I want to do the whole thing myself/recreate the wheel/etc) must [b]NOT[/b] be a part of your thought process.Hmmm, getting too long winded here.Bottom line, look at this link and consider it as a possibility.http://www.nstoia.com/toh/technical/clientsideresize/index.phpAgain, [color=red][u][b]my sincere apologies [/b] [/u] [/color] for being somewhat 'off-topic'.Lite... Quote Link to comment https://forums.phpfreaks.com/topic/13467-apologies-first-image-uploading/ Share on other sites More sharing options...
litebearer Posted July 2, 2006 Author Share Posted July 2, 2006 No offense; however, my understanding (and I may be wrong - as I was twice in my life - once in 1968 and again in 1979) PHP/GD cannot resize an image [b][u][i][color=red]BEFORE[/color][/i][/u][/b] it gets to the server. If I am wrong, I stand corrected and apologize for my ignorance.Lite... Quote Link to comment https://forums.phpfreaks.com/topic/13467-apologies-first-image-uploading/#findComment-52039 Share on other sites More sharing options...
Drumminxx Posted July 2, 2006 Share Posted July 2, 2006 the only problem with that is will all your users have it installed on their computers?might work good on a local intranet site or a small family type site as they describe where you can tell your users to install this first. :'( according to my wife I'm always wrong Quote Link to comment https://forums.phpfreaks.com/topic/13467-apologies-first-image-uploading/#findComment-52041 Share on other sites More sharing options...
litebearer Posted July 2, 2006 Author Share Posted July 2, 2006 Not to get into a dispute here, as my original/current intent was/is to simplify life, if one reads my posts correctly, it becomes evident that from the start I have acknowledged the ability of PHP/GD to do image manipulations. The whole point of the post was/is to provide a possible approach to reduce upload time and to reduce the occurrence of errors due to size. NOWWHERE in my posts have I detracted from nor implied that php/gd is incapable of nor deficient in performing image manipluations.Lite... Quote Link to comment https://forums.phpfreaks.com/topic/13467-apologies-first-image-uploading/#findComment-52046 Share on other sites More sharing options...
Orio Posted July 2, 2006 Share Posted July 2, 2006 litebearer came with a tip for everyone to install this software so your image uploading will be faster. Thats it. How did this get to Gd??Orio. Quote Link to comment https://forums.phpfreaks.com/topic/13467-apologies-first-image-uploading/#findComment-52053 Share on other sites More sharing options...
Drumminxx Posted July 2, 2006 Share Posted July 2, 2006 its ok redarrow were used to it :)just kidding[quote author=redarrow link=topic=99199.msg390557#msg390557 date=1151860055]so so so sorry i thort the post was how to do what was said so sorry.the link as provided is good know have looked at it.why dont these good links get posted in the forum for others or as a sticky cheers.once agin i am sorry.as reading this is the posted solution thank you so much<?php function Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path) { $s_path = trim($s_path); $o_path = trim($o_path); $save = $s_path . $save; $file = $o_path . $file; $ext = strtolower(end(explode('.',$save))); list($width, $height) = getimagesize($file) ; if(($width>$t_w) OR ($height>$t_h)) { $r1 = $t_w/$width; $r2 = $t_h/$height; if($r1<$r2) { $size = $t_w/$width; }else{ $size = $t_h/$height; } }else{ $size=1; } $modwidth = $width * $size; $modheight = $height * $size; $tn = imagecreatetruecolor($modwidth, $modheight) ; switch ($ext) { case 'jpg': case 'jpeg': $image = imagecreatefromjpeg($file) ; break; case 'gif': $image = imagecreatefromgif($file) ; break; case 'png': $image = imagecreatefrompng($file) ; break; } imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; imagejpeg($tn, $save, 100) ; return; } ##################### # # Example usage # ##################### $save = 'myfile.jpg'; $file = 'original.jpg'; $t_w = 120; $t_h = 120; $o_path = " "; $s_path = " "; Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path); ?> [/quote] Quote Link to comment https://forums.phpfreaks.com/topic/13467-apologies-first-image-uploading/#findComment-52060 Share on other sites More sharing options...
litebearer Posted July 2, 2006 Author Share Posted July 2, 2006 So am I still at 2 (1968 & 1979) or is it 3? just kidding. I take no personal offense to anything except someone kicking my dog. ;)Lite... Quote Link to comment https://forums.phpfreaks.com/topic/13467-apologies-first-image-uploading/#findComment-52063 Share on other sites More sharing options...
redarrow Posted July 2, 2006 Share Posted July 2, 2006 can someone kindly really really harshly comment the code right out cheers.<?php function Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path) { $s_path = trim($s_path); $o_path = trim($o_path); $save = $s_path . $save; $file = $o_path . $file; $ext = strtolower(end(explode('.',$save))); list($width, $height) = getimagesize($file) ; if(($width>$t_w) OR ($height>$t_h)) { $r1 = $t_w/$width; $r2 = $t_h/$height; if($r1<$r2) { $size = $t_w/$width; }else{ $size = $t_h/$height; } }else{ $size=1; } $modwidth = $width * $size; $modheight = $height * $size; $tn = imagecreatetruecolor($modwidth, $modheight) ; switch ($ext) { case 'jpg': case 'jpeg': $image = imagecreatefromjpeg($file) ; break; case 'gif': $image = imagecreatefromgif($file) ; break; case 'png': $image = imagecreatefrompng($file) ; break; } imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; imagejpeg($tn, $save, 100) ; return; } ##################### # # Example usage # ##################### $save = 'myfile.jpg'; $file = 'original.jpg'; $t_w = 120; $t_h = 120; $o_path = " "; $s_path = " "; Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path); ?> Quote Link to comment https://forums.phpfreaks.com/topic/13467-apologies-first-image-uploading/#findComment-52066 Share on other sites More sharing options...
litebearer Posted July 2, 2006 Author Share Posted July 2, 2006 Well....The first thing I noticed that is very poorly done is there is a lack of good error trapping.Lite... Quote Link to comment https://forums.phpfreaks.com/topic/13467-apologies-first-image-uploading/#findComment-52068 Share on other sites More sharing options...
Drumminxx Posted July 2, 2006 Share Posted July 2, 2006 I would say your still at 2. What you found works provided the user has that software.now if javascript could resize the image on the client before it gets sent to the server we could just add that script to our pages and life would be easier, unfortunantly javascript does not have that type of functionality so yours may be the only solution.[quote author=litebearer link=topic=99199.msg390563#msg390563 date=1151860502]So am I still at 2 (1968 & 1979) or is it 3? just kidding. I take no personal offense to anything except someone kicking my dog. ;)Lite...[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/13467-apologies-first-image-uploading/#findComment-52096 Share on other sites More sharing options...
corbin Posted July 2, 2006 Share Posted July 2, 2006 No offense but i wouldnt consider ever installing that software... Sounds like a good idea, but what if the person only wants to upload 1 image or something? Quote Link to comment https://forums.phpfreaks.com/topic/13467-apologies-first-image-uploading/#findComment-52135 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.