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.


implement problems
Goto page 1, 2  Next
 
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
ijasont
Newbie


Joined: 18 Jun 2004
Posts: 12

PostPosted: Fri Jun 18, 2004 5:19 am    Post subject: implement problems Reply with quote

First off let me say "WOW! "
Second let me say "goto 10" if I can ever get this right.

What I am trying to do is probably very very easy, but then again I'm a total n00b...and an idiot to boot!

Basically I want to use the visual 'fancy' java to be able to edit and save images that are already uploaded onto my site.
I am working with these Vars
$name -- this sends in the full name of the image
$path -- this tells teh script where to save the image

so all I need to know is exactly how to call the right scripts (I have them all downloaded/uploaded) to perform the easy task.

Sorry for being a dunce on this. I tried all the sample codes but still am to new to really figure out how to just use the Visual Interface to Edit and Save a specific image.
Back to top
View user's profile Send private message Visit poster's website
ijasont
Newbie


Joined: 18 Jun 2004
Posts: 12

PostPosted: Fri Jun 18, 2004 5:38 am    Post subject: Reply with quote

ok I got the interface to work using code listed on another thread

Code:

<?php
$name = $_GET['name'];
require_once 'class.cropinterface.php';
$ci = new cropInterface();
if ($_GET['file']) {
$ci->loadImage($_GET['file']);
$ci->cropToDimensions($_GET['sx'], $_GET['sy'], $_GET['ex'], $_GET['ey']);
header('Content-type: image/jpeg');
$ci->showImage('jpg', 100);
exit;
 } else {
$ci->loadInterface('$name');
$ci->loadJavaScript();
}
?>


Now I'll I need to do is add in a way to save the now cropped image.


Last edited by ijasont on Fri Jun 18, 2004 6:47 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
ijasont
Newbie


Joined: 18 Jun 2004
Posts: 12

PostPosted: Fri Jun 18, 2004 6:38 am    Post subject: Reply with quote

edited:
I fixed the problem I had in this post. Just need to figure the save part now.
Back to top
View user's profile Send private message Visit poster's website
amnuts
Site Admin


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

PostPosted: Fri Jun 18, 2004 9:06 am    Post subject: Reply with quote

Hi there, and welcome to the baord! Smile

I'm glad you got the first problem sorted out yourself - it's always rewarding to do that, eh? Saving is really easy, just use the 'saveImage' method, which is found i nthe class.cropcanvas.php file.

So taking the code you poste dup, it might look like:

PHP:
<?php

$name 
$_GET['name']; 
require_once 
'class.cropinterface.php'
$ci = new cropInterface(); 

if (
$_GET['file']) { 
    
$ci->loadImage($_GET['file']); 
    
$ci->cropToDimensions($_GET['sx'], $_GET['sy'], $_GET['ex'], $_GET['ey']); 
    
$ci->saveImage('/path/to/save/to.jpg'90);
    
// now you can do something else here if you want
    // like give a message, or redirect, or something 
} else { 
    
$ci->loadInterface($name); 
    
$ci->loadJavaScript(); 


?>


And there you go! Smile By the way, don't do this:

$ci->loadInterface('$name');

Because the literal string '$name' will be used, and not what is contain in the $name variable. (The single quotes don't allow for variable translation).

Let me know if you have problems.

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


Joined: 18 Jun 2004
Posts: 12

PostPosted: Fri Jun 18, 2004 9:18 am    Post subject: Reply with quote

heya wow that wa fast!

The only other problem I am having is with paths. These files are here"
www.mysite.com/admin/12crop/test2.php
and the images I am trying to load in are here
www.mysite.com/img/loot/somepic.jpg

It all actually works out when I do this:
Code:
 
$img = '/img/loot/drum.jpg';
$source = $DOCUMENT_ROOT . $img;

expect I cannot see that img during editing do to a bad path here:
Code:
echo '<tr><td><img src="', $this->file, '" ', $this->img['sizes'][3], ' alt="crop this image" name="theImage"></td></tr>', "\n";


I've been messing with this for hours and cannot seem to be able to get the path right so I can see the img during editing. It recognizes the img name, size and everything I just cannot see it until I submit it.
Back to top
View user's profile Send private message Visit poster's website
amnuts
Site Admin


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

PostPosted: Fri Jun 18, 2004 9:31 am    Post subject: Reply with quote

When you load the crop interface, what file name are you passing? Is it $img or $source?
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
ijasont
Newbie


Joined: 18 Jun 2004
Posts: 12

PostPosted: Fri Jun 18, 2004 9:33 am    Post subject: Reply with quote

as it is now I pass $source

If I dont the File_exists function cannot detect the img.
Back to top
View user's profile Send private message Visit poster's website
ijasont
Newbie


Joined: 18 Jun 2004
Posts: 12

PostPosted: Fri Jun 18, 2004 9:41 am    Post subject: Reply with quote

BAH! I got it.
I have to pass two Vars
Code:

 } else {
 $img = '/img/loot/drum.jpg';
 $source = $DOCUMENT_ROOT . $img;
$ci->loadInterface($source,$img);
$ci->loadJavaScript();
}

The just as a class this->image = $img and use this->image instead of this-> file in the imgsrc line.

wow that only took 4 hours to figure out! I must be getting good at this!

Very Happy

btw: $img is soon be a $img = $_GET but for testing I am using a absolute path to make it easier
Back to top
View user's profile Send private message Visit poster's website
amnuts
Site Admin


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

PostPosted: Fri Jun 18, 2004 9:53 am    Post subject: Reply with quote

Well done for working it out. The solution I was going to suggest (which I may implement myself) is to remove the document_root from the filename in the loadInterface method, such as:

PHP:
<?php echo '<tr><td><img src="'$this->file'" '$this->img['sizes'][3], ' alt="crop this image" name="theImage"></td></tr>'"\n"?>


would then be:

PHP:
<?php echo '<tr><td><img src="'str_replace($_SERVER['DOCUMENT_ROOT'], ''$this->file), '" '$this->img['sizes'][3], ' alt="crop this image" name="theImage"></td></tr>'"\n"?>


That way you only have to pass the original one parameter.

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


Joined: 18 Jun 2004
Posts: 12

PostPosted: Fri Jun 18, 2004 10:04 am    Post subject: Reply with quote

ahh yeah that probably would be cleaner and a tab bit more flexible.

BTW. I did not see a saveImage() in the ci files. I just went over and copied the function from the cc file into the ci file.
I am currently using this:
Code:

$newName = woot; //will be a random var but use this for testing
 $ci-> saveImage ("{$newName}.jpg");

The quality is inside the saveImage faction for now but I may move that out to give a bit more functionality later.
Back to top
View user's profile Send private message Visit poster's website
amnuts
Site Admin


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

PostPosted: Fri Jun 18, 2004 10:12 am    Post subject: Reply with quote

ijasont wrote:
BTW. I did not see a saveImage() in the ci files. I just went over and copied the function from the cc file into the ci file.


Oooooo... no, no. Copy the entire class.cropcanvas.php file into the same directory as the class.cropinterface.php file, because the interface class extends the base crop canvas class, which is where all the cropping functionality lies. That is where the load, save, crop, flush, etc. methods lie. The crop interface class just kind of 'sits on top' of the crop canvas class to add the additional functionality of an interface.

Also, the quality of the image can be passed along to the saveImage method, so you can control it easily (the saveImage that's in the crop canvas class, anyway!)

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


Joined: 18 Jun 2004
Posts: 12

PostPosted: Fri Jun 18, 2004 10:58 am    Post subject: Reply with quote

ahh IC. I didn't see how they all inter-link within the ci file.

I am very new to GD and I have a lot of work to do with images on my site. It's pretty amazing to kow that I can do pretty much anything I want to within these classes.

Thank you so much to taking the time to not only write these but to support them as well.
Back to top
View user's profile Send private message Visit poster's website
amnuts
Site Admin


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

PostPosted: Fri Jun 18, 2004 11:09 am    Post subject: Reply with quote

No problem - my pleasure! Smile

Just to clarify something; it's not GD that makes the classes interact, but PHP. You'll notice something like this in the code:

class cropInterface extends cropCanvas

This just that the cropInterface class inherits all the functionality of the cropCanvas class and then can build on to it, use all it's methods, and so on. If you have something like this you need to make sure you have the original class (the parent class) required or included somewhere.

If you want to play around with GD some more, then check out the dropShadow class. It's basically a fairly powerful image resizer that can also wrap a set of dropshadow images around the thumbnail. And there's also the imageMask class which you can use to apply a mask over an image, such as PhotoShop of Gimp might do. I've also extended that personally to include an overlay effect (see: http://php.amnuts.com/forums/viewtopic.php?t=94)

Lots you can do... Have fun! Smile

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


Joined: 18 Jun 2004
Posts: 12

PostPosted: Fri Jun 18, 2004 5:50 pm    Post subject: Reply with quote

One last thing.
I am eventually going to make this editing feature open to the public and I noticed that once I Submit this image to be edited it shows the DocumentRoot url in the URL line.
This means everyone will see my full url string:
mysite.com/12crop/lootedit.php?file=/home/USERNAME/public_html/img/loot/drum.jpg

is there a way to aviod this?
Back to top
View user's profile Send private message Visit poster's website
amnuts
Site Admin


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

PostPosted: Fri Jun 18, 2004 6:14 pm    Post subject: Reply with quote

sure... Just use the filename in the query string, such as:

mysite.com/12crop/lootedit.php?file=drum.jpg

then build up the filename in the PHP, such as:

$filename = $_SERVER['DOCUMENT_ROOT'] . '/img/loot/' . $_GET['file'];

Do some sanity checks on the $_GET['file'] variable first, such as checking it exists and doesn't have invalid characters (such as ;, /, etc.)

If you already have the full path and don't want that in your query string, just do:

echo 'mysite.com/12crop/lootedit.php?file=', basename($fullpath);

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
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
Goto page 1, 2  Next
Page 1 of 2

 
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