andy's php projects
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Script and site usage:
All of the scripts on this site are provided free for non-commerical, personal or non-profit use. If you find these scripts useful to you, appreciate the free support, or are just an all round nice person, then why not donate a little dosh? If you wish to use any of these in a commercial system, please refer to the payment plan.


Save the cropped pic 2 times

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    php.amnuts.com Forum Index -> Crop Canvas
View previous topic :: View next topic  
Author Message
EssEt
Newbie


Joined: 21 Dec 2004
Posts: 12

PostPosted: Wed Mar 09, 2005 2:37 am    Post subject: Save the cropped pic 2 times Reply with quote

Hi everyone!

i want my crop tool to first choose pic from harddrive (done)
Then the file i choose is being uploaded to the server in (images/orginal/)
Then i want to crop that pic and save the cropped pic to (images/avatars/)
so i can do a link to the original pic by clicking the small pic!

And i want the crop area to by non-sizeble ... The area to crop is just for moving around and select area to crop... so the pic cannot be smaller or bigger than the alredy set height & width on the crop area!

Thx for a great project... its so awsome!
Greets // EssEt
Back to top
View user's profile Send private message Send e-mail
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Wed Mar 09, 2005 9:10 am    Post subject: Re: Save the cropped pic 2 times Reply with quote

EssEt wrote:
And i want the crop area to by non-sizeble ... The area to crop is just for moving around and select area to crop... so the pic cannot be smaller or bigger than the alredy set height & width on the crop area!


This part was answered in your other thread.

EssEt wrote:
i want my crop tool to first choose pic from harddrive (done)
Then the file i choose is being uploaded to the server in (images/orginal/)
Then i want to crop that pic and save the cropped pic to (images/avatars/)
so i can do a link to the original pic by clicking the small pic!


If you have the uploading done, which parts are you still having problems with? Clarify and I'll try to help!

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
EssEt
Newbie


Joined: 21 Dec 2004
Posts: 12

PostPosted: Wed Mar 09, 2005 10:07 am    Post subject: hi Reply with quote

well i can upload a file and crop it... as the script should work!

When i upload "picture.jpg" the pic lands in "image/upload/picture.jpg"
Then i crop it and the pic is being overwritten, "image/upload/picture.jpg" is now cropped...

What i want is that the cropped pic is saved in another directory and to the users id like: "images/users/23.jpg"

I use sessions on my site but cant get the session to work in the crop interface... the headers dont allow me to integrate
Back to top
View user's profile Send private message Send e-mail
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Wed Mar 09, 2005 11:43 am    Post subject: Re: hi Reply with quote

EssEt wrote:
When i upload "picture.jpg" the pic lands in "image/upload/picture.jpg"
Then i crop it and the pic is being overwritten, "image/upload/picture.jpg" is now cropped...

What i want is that the cropped pic is saved in another directory and to the users id like: "images/users/23.jpg"


Not having seen your code this is a guess (but a good guess, mind you. Wink )

If you're using the $_GET['filename'] as your 'image to crop' and then 'image to save', then it will naturally overwrite your original file (the original file is used in the loadInterface, after all). What you need to do is just supply a different path/filename for the saveImage() method.

EssEt wrote:
I use sessions on my site but cant get the session to work in the crop interface... the headers dont allow me to integrate


Did you start the session before everything else? You need to use session_start() before any http headers are sent. Alternatively, you could always just use ob_start() to capture the buffer (which implicitly goes to the brwoser otherwise, thereby sending an http header) and you can then use session_start anywhere under that.

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
EssEt
Newbie


Joined: 21 Dec 2004
Posts: 12

PostPosted: Wed Mar 09, 2005 12:00 pm    Post subject: Reply with quote

hi ... here are the codes

CHANGE.PHP
PHP:
<?php function CropUserPic()
    {
        
ob_start();
        
$filename $_FILES['avtar_upload']['name'];
        if (
move_uploaded_file($_FILES['avtar_upload']['tmp_name'], CROP_DIR $filename))
        {
        
header("Location: crop.php?avtar_upload=$filename");
        }
        
ob_end_flush();
    } 
?>


CROP.PHP
PHP:
<?php

    session_start
();
    
header("Cache-control: private");

    if (
file_exists("includes/configure.php"))
    {
    require_once(
"includes/configure.php");
    }
    else
    {
        echo 
"FEL I CONFIGURE.PHP";
        return;
    }
    
    require_once(
LANGUAGE);
    if (!
function_exists('file_get_contents')) 
    { 
    
    function 
file_get_contents($filename$use_include_path 0
    { 
                
$file = @fopen($filename'rb'$use_include_path); 
                if (
$file
                { 
                if (
$fsize = @filesize($filename)) 
                { 
                
$data fread($file$fsize); 
                } 
                else 
                { 
                while (!
feof($file)) 
                { 
                
$data .= fread($file1024); 
                } 
                } 
                
fclose($file); 
                }
    return 
$data
    } 
    }
    
    
// SQL
    
@$connect mysql_connect(MYSQL_ADDRESSMYSQL_USERNAMEMYSQL_PASSWORD) or die($lang[error_db]);
    
define ("CONNECT"$connect);
    
mysql_select_db(MYSQL_DATABASE);
    
    require(
"includes/theme.php");
    
$theme = new Theme();
    
$theme->GetTheme();
    require(
"includes/user.php");
    
    require_once (
"includes/cropinterface.php");
    
    
$ci =& new cropInterface(); 
    if (isset(
$_GET['avtar_upload']) && isset($_GET['sx'])) 
    { 
        
$ci->loadImage($_GET['avtar_upload']); 
        
$ci->cropToDimensions($_GET['sx'], $_GET['sy'], $_GET['ex'], $_GET['ey']); 
        
$ci->saveImage($_GET['avtar_upload']);
//header('Content-type: image/jpeg');
        
$ci->showImage('jpg'90);
        exit;
    }
    
?>    
<html>

<head>
    <style type="text/css">
        body, td, p
        {
            font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif;
            font-size: 10px;
        }
        
        #submit
        {
            font-size: 10px;
            font-family: "MS Sans Serif", Geneva, sans-serif;
            height: 23px;
            background-color: #D4D0C8;
            border: 0px;
            padding: 3px,5px,3px,5px;
            width: 100%;
        }
    </style>
</head>
<body>
<?php


        $ci
->loadInterface(CROP_DIR $_GET['avtar_upload']); 
        
$ci->loadJavaScript();

?>


And the cropinterface.php
PHP:
<?php
require("includes/cropcanvas.php");
    
class 
cropInterface extends canvasCrop
{
    var 
$file;
    var 
$img;
    var 
$crop;
    var 
$useFilter;


    
/**
    * @return cropInterface
    * @param bool $debug
    * @desc Class initializer
    */
    
function cropInterface($debug false)
    {
        
parent::canvasCrop($debug);
        
        
$this->img  = array();
        
$this->crop = array();
        
$this->useFilter false;

        
$agent trim($_SERVER['HTTP_USER_AGENT']);
        if ((
stristr($agent'wind') || stristr($agent'winnt')) && (preg_match('|MSIE ([0-9.]+)|'$agent) || preg_match('|Internet Explorer/([0-9.]+)|'$agent)))
        {
            
$this->useFilter true;
        }
        else
        {
            
$this->useFilter false;
        }
        
$this->setResizing();
        
$this->setCropMinSize();
    }

    
    
/**
    * @return void
    * @param unknown $do
    * @desc Sets whether you want resizing options for the cropping area.
    * This is handy to use in conjunction with the setCropSize function if you want a set cropping size.
    */
    
function setResizing($do true)
    {
        
$this->crop['resize'] = ($do) ? true false;
    }
    
    
    
/**
    * @return void
    * @param int $w
    * @param int $h
    * @desc Sets the initial size of the cropping area.
    * If this is not specifically set, then the cropping size will be a fifth of the image size.
    */
    
function setCropDefaultSize($w$h)
    {
        
$this->crop['width']  = ($w 5) ? $w;
        
$this->crop['height'] = ($h 5) ? $h;
    }
    
    
    
/**
    * @return void
    * @param int $w
    * @param int $h
    * @desc Sets the minimum size the crop area can be
    */
    
function setCropMinSize($w 25$h 25)
    {
        
$this->crop['min-width']  = ($w 5) ? $w;
        
$this->crop['min-height'] = ($h 5) ? $h;
    }
    

    
/**
    * @return void
    * @param string $filename
    * @desc Load the cropping interface
    */
    
function loadInterface($filename)
    {
        if (!
file_exists($filename))
        {
            die(
"The file '$filename' cannot be found.");
        }
        else
        {
            
$this->avtar_upload $filename;
            
$this->img['sizes'] = getimagesize($filename);
            if (!
$this->crop['width'] || !$this->crop['height'])
            {
                
$this->setCropDefaultSize(($this->img['sizes'][0] / 5), ($this->img['sizes'][1] / 5));
            }
        }
        echo 
'<script type="text/javascript" src="includes/crop.js"></script>'"\n";
        echo 
'<div id="theCrop" style="position:absolute;background-color:transparent;border:1px solid yellow;width:'$this->crop['width'], 'px;height:'$this->crop['height'], 'px;';
        if (
$this->useFilter)
        {
            echo 
'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'images/crop/transbg.png\',sizingMethod=\'scale\');';
        }
        else
        {
            echo 
'background-image:url(images/crop/transbg.png);';
        }
        echo 
"\"></div>\n";
        echo 
'<table border="1" style="border-collapse:collapse; border:1px solid black; width:'$this->img['sizes'][0], 'px;" align="center">';
        echo 
'<tr><td align="center" style="padding:5px;"><strong>'basename($this->avtar_upload), ' ('$this->img['sizes'][0], ' x '$this->img['sizes'][1], ')</strong>';
        if (
$this->crop['resize'])
        {
            echo 
'<br><br>H?ll ner shift eller ctrl f?r fixering av storleken p? crop omr?det';
        }
        echo 
"</td></tr>\n";
        echo 
'<tr><td><img src="'$this->avtar_upload'" '$this->img['sizes'][3], ' alt="crop this image" name="theImage"></td></tr>'"\n";
        if (
$this->crop['resize'])
        {
            echo 
'<tr><td align="center" style="font-size:11px;vertical-align:middle;padding:5px;"><input type="radio" id="resizeAny" name="resize" onClick="my_SetResizingType(0);" checked> <label for="resizeAny">Oberoende Storlek</label> &nbsp; <input type="radio" name="resize" id="resizeProp" onClick="my_SetResizingType(1);"> <label for="resizeProp">Fast Storlek</label></td></tr>'"\n";
        }
        echo 
'<tr><td><input type="submit" value="JAG ?R KLAR - BESK?R MIN BILD" style="width:100%;" id="submit" onClick="my_Submit();"></td></tr>';
        echo 
"\n</table>\n";
    }
    
    
    
/**
    * @return void
    * @desc Load the javascript required for a functional interface.
    * This MUST be called at the very end of all your HTML, just before the closing body tag.
    */
    
function loadJavaScript()
    {
        
$params '"theCrop"+MAXOFFLEFT+0+MAXOFFRIGHT+' $this->img['sizes'][0] . '+MAXOFFTOP+0+MAXOFFBOTTOM+' $this->img['sizes'][1] . ($this->crop['resize'] ? '+RESIZABLE' '') . '+MAXWIDTH+' $this->img['sizes'][0] . '+MAXHEIGHT+' $this->img['sizes'][1] . '+MINHEIGHT+' $this->crop['min-height'] . '+MINWIDTH+' $this->crop['min-width'] . ',"theImage"+NO_DRAG';
        echo <<< EOT
<script type="text/javascript">
<!--

    SET_DHTML(
$params);

    dd.elements.theCrop.moveTo(dd.elements.theImage.x, dd.elements.theImage.y);
    dd.elements.theCrop.setZ(dd.elements.theImage.z+1);
    dd.elements.theImage.addChild("theCrop");
    dd.elements.theCrop.defx = dd.elements.theImage.x;

    function my_DragFunc()
    {
        dd.elements.theCrop.maxoffr = dd.elements.theImage.w - dd.elements.theCrop.w;
        dd.elements.theCrop.maxoffb = dd.elements.theImage.h - dd.elements.theCrop.h;
        dd.elements.theCrop.maxw    = 
{$this->img['sizes'][0]};
        dd.elements.theCrop.maxh    = 
{$this->img['sizes'][1]};
    }

    function my_ResizeFunc()
    {
        dd.elements.theCrop.maxw = (dd.elements.theImage.w + dd.elements.theImage.x) - dd.elements.theCrop.x;
        dd.elements.theCrop.maxh = (dd.elements.theImage.h + dd.elements.theImage.y) - dd.elements.theCrop.y;
    }
    
    function my_Submit()
    {
        self.location.href = 'crop.php?avtar_upload=
{$this->avtar_upload}&sx=' + 
            (dd.elements.theCrop.x - dd.elements.theImage.x) + '&sy=' + 
            (dd.elements.theCrop.y - dd.elements.theImage.y) + '&ex=' +
            ((dd.elements.theCrop.x - dd.elements.theImage.x) + dd.elements.theCrop.w) + '&ey=' +
            ((dd.elements.theCrop.y - dd.elements.theImage.y) + dd.elements.theCrop.h);
    }
    
    function my_SetResizingType(proportional)
    {
        if (proportional)
        {
            dd.elements.theCrop.scalable  = 1;
            dd.elements.theCrop.resizable = 0;
        }
        else
        {
            dd.elements.theCrop.scalable  = 0;
            dd.elements.theCrop.resizable = 1;
        }
    }
    
//-->
</script>
EOT;
        }
}

?>
Back to top
View user's profile Send private message Send e-mail
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Wed Mar 09, 2005 12:28 pm    Post subject: Reply with quote

Wow... Lots of code! I changed the 'code' tags to 'php' tags - makes it more readable, I think.

Well, as I suspected, you're using the wrong file location for your save:

PHP:
<?php $ci->saveImage($_GET['avtar_upload']); ?>


That's eaxactly the same image as you uploaded, so you'd end up overwriting that. Give it a different path/filename for that line.

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
EssEt
Newbie


Joined: 21 Dec 2004
Posts: 12

PostPosted: Wed Mar 09, 2005 1:34 pm    Post subject: Reply with quote

thnx ... now the main problem is solved... but the session is still not working... now i have session start at the top and this code to save with!

Code:
$ci->saveImage($_SESSION['usr_name'], 90);


Why?... i have all the necessary stuff in there...
Back to top
View user's profile Send private message Send e-mail
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Wed Mar 09, 2005 5:03 pm    Post subject: Reply with quote

Hmm.. Unless the session could get started, in which case you should see some error response (either on screen or in the error log file), then then only other reason I can think of is that the session variable doesn't have the require information in there.

But then, why use session at all? You've already got a config file, and you have constants defined in there such as CROP_DIR. Why not just add an AVATAR_DIR in there and do something like:

PHP:
<?php $ci->saveImage(AVATAR_DIR basename($_GET['filename']), 90); ?>


Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
EssEt
Newbie


Joined: 21 Dec 2004
Posts: 12

PostPosted: Wed Mar 09, 2005 5:24 pm    Post subject: Reply with quote

Yeah ... that one is working... i tried that but i want the pic to be named as their id in the user table...

1.jpg
56.jpg
45.jpg

everyone has a diffrent id in the table and its uniq to their profile... how do i else get their id? hmm....
Back to top
View user's profile Send private message Send e-mail
EssEt
Newbie


Joined: 21 Dec 2004
Posts: 12

PostPosted: Wed Mar 09, 2005 5:30 pm    Post subject: Reply with quote

and @ the same time i want the database update the users row!

PHP:
<?php $sql "UPDATE ".MYSQL_PREFIX."_users SET u_pic = '".$filename."' WHERE u_id = '".USER_ID."'";
mysql_query($sqlCONNECT); ?>


Its all 4 my avatar upload on my site... so for the avatar to show in the right persons profile i need the users id to show when he uploads and crop the image!
Back to top
View user's profile Send private message Send e-mail
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Wed Mar 09, 2005 6:17 pm    Post subject: Reply with quote

EssEt wrote:
Yeah ... that one is working... i tried that but i want the pic to be named as their id in the user table...

1.jpg
56.jpg
45.jpg

everyone has a diffrent id in the table and its uniq to their profile... how do i else get their id? hmm....


In that case it does seem to make sense to use the session information. I don't see where you're setting that, so just verify that you're only using the $_SESSION['usr_name'] after the session_start() has been used. Try just testing you have the $_SESSION array populated before you try to save by doing a print_r($_SESSION).

Also, you'll probably want this:

PHP:
<?php $ci->saveImage($_SESSION['usr_name'] . '.jpg'90); ?>


otherwise you'll just get files saved called '48', '3', '19', and so on, and not '48.jpg', '3.jpg', etc.

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
EssEt
Newbie


Joined: 21 Dec 2004
Posts: 12

PostPosted: Wed Mar 09, 2005 6:56 pm    Post subject: Reply with quote

Yeah i got that to work now... it saves the cropped file to 1.jpg an the original file to org_1.jpg

But when i am going to crop another pic to change avatar the files are already there and the file i uploaded doesnt show! the old file is now showing in the interface with the new files size..?

Cant i unlink the old ones in the process when i am going to upload a new?
Back to top
View user's profile Send private message Send e-mail
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Thu Mar 10, 2005 4:45 am    Post subject: Reply with quote

You can unlink before you do the move_uploaded code (after the upload). But if the file being uploaded/moved has the same name as the existing file then it should over-write it. So I would first check to see that your browser isn't actually caching the image it thinks should be in the interface.

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
EssEt
Newbie


Joined: 21 Dec 2004
Posts: 12

PostPosted: Thu Mar 10, 2005 12:26 pm    Post subject: Reply with quote

Hi! now is all of the problems solved... thanx sooo much! just love your passion for this... the support is the best you can get and the script is t die for!

I was reading this post http://php.amnuts.com/forums/viewtopic.php?t=107 and i loved the ideea of several already set areas and that you just can set the area proportional (scale)...

How can i get that? it would be just lovley!

Thnx for the help so far anyway...
//EssEt
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    php.amnuts.com Forum Index -> Crop Canvas All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group