Jump to content

Apologies first, Image uploading....


litebearer

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...
Link to comment
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...
Link to comment
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
Link to comment
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...
Link to comment
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]
Link to comment
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);
?>

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.