Jump to content


Photo

Apologies first, Image uploading....


  • Please log in to reply
10 replies to this topic

#1 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 02 July 2006 - 04:34 PM

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 PRIOR to uploading.

The answer (and it is correct) inevitably is - 'You cannot do that, as PHP is server-side, therefore, the image MUST get to the server before PHP can resize/check size etc.'.

As a businessman/crisis-management consultant/non-programmer-programmer, my objective is to accomplish the mission using whatever tools are efficient and readily available. Ego (I want to do the whole thing myself/recreate the wheel/etc) must NOT 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.co...esize/index.php


Again, my sincere apologies for being somewhat 'off-topic'.

Lite...

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#2 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 02 July 2006 - 04:44 PM

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 BEFORE it gets to the server.

If I am wrong, I stand corrected and apologize for my ignorance.

Lite...

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#3 Drumminxx

Drumminxx
  • Members
  • PipPipPip
  • Advanced Member
  • 92 posts
  • LocationUSA

Posted 02 July 2006 - 04:44 PM

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
:: gucci.com ::
:: blockbuster.com ::

--------------------

#4 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 02 July 2006 - 04:52 PM

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...

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#5 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 02 July 2006 - 05:03 PM

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.
Think you're smarty?

(Gone until 20 to November)

#6 Drumminxx

Drumminxx
  • Members
  • PipPipPip
  • Advanced Member
  • 92 posts
  • LocationUSA

Posted 02 July 2006 - 05:10 PM

its ok redarrow were used to it  :)

just kidding


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);
?>






:: gucci.com ::
:: blockbuster.com ::

--------------------

#7 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 02 July 2006 - 05:15 PM

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...


all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#8 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 July 2006 - 05:18 PM

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);
?>


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#9 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 02 July 2006 - 05:22 PM

Well....

The first thing I noticed that is very poorly done is there is a lack of good error trapping.

Lite...

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#10 Drumminxx

Drumminxx
  • Members
  • PipPipPip
  • Advanced Member
  • 92 posts
  • LocationUSA

Posted 02 July 2006 - 06:10 PM

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.


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...



:: gucci.com ::
:: blockbuster.com ::

--------------------

#11 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 02 July 2006 - 06:49 PM

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?
Why doesn't anyone ever say hi, hey, or whad up world?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users