Jump to content

Archived

This topic is now archived and is closed to further replies.

litebearer

Apologies first, Image uploading....

Recommended Posts

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


Again, [color=red][u][b]my sincere apologies [/b] [/u] [/color] for being somewhat 'off-topic'.

Lite...

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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);
?>

Share this post


Link to post
Share on other sites
Well....

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

Lite...

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

×

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.