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.


Crop + Shadow?

 
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 -> Drop Shadowed Thumbnail Creator
View previous topic :: View next topic  
Author Message
TheBuggerGuy
Newbie


Joined: 29 Mar 2004
Posts: 13

PostPosted: Thu May 27, 2004 11:45 pm    Post subject: Crop + Shadow? Reply with quote

Its me again...

This thumbnail creator is great because it can create thumbnails, add shadows and reduce the amount of files you have on your site. But, what if you have large pictures that, when made into a thumbnail, are fairly unidentifiable from each other?

Is there a way to embed a 'cropping' feature to this script?
(I am aware that you already have a cropping script, but I want the two together if you may.)

Here's my current code:
PHP:
<?php 

    
require_once "class.dropshadow.php"

    
$ds = new dropShadow(FALSE); 
    
$ds->setShadowPath('./'); 
    
$ds->loadImage("./../../{$_GET['input']}"); 

    
$size getimagesize("./../../{$_GET['input']}"); 
    if (
$size[0] > $size[1]) { 
        
$ds->resizeToSize($_GET['maxsize'], 0); 
    } else { 
        
$ds->resizeToSize(0$_GET['maxsize']); 
    } 

    if (
$_GET['shadow'] == 1) { 
        
$ds->applyShadow($_GET['colour']); 
        
$ds->showShadow('jpg'); 
    } else { 
        
$ds->showFinal('jpg');      
    } 

?>


I use the script via the address, so if I have many images, I can just <img src="shadow.php?settings=...">

Edit: For more clarity, I'll give your my current situation. My photo gallery uses normal the shadow script to generate the thubnails. I'm in the stage of making an optical illusions gallery where, since most are fairly large, it would be useless just to 'resize'. I would prefer to crop them. Maybe to get the top-corner of the image so people can get an idea of what it's about.

2nd Edit: It occurred to me it may be better to make another thumbnail-shadow-crop script (and use that for the illusions only) rather than modify the original script which is already useful as is.
Back to top
View user's profile Send private message
amnuts
Site Admin


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

PostPosted: Fri May 28, 2004 3:21 am    Post subject: Reply with quote

Here's what I would do...

Rather than re-writing or hacking the dropshadow class, just extend it. This way you have all the benefits of the shadow class (which I should really rename because it's a really powerful resizer with the added bonus of being able to wrap drop shadows around an image!) but it's still stand-alone enough that you could use it elsewhere.

For example, I put togetehr a little extension class yesterday to resize an image and then overlay a PNG on top of that, giving a nice beveled/stroked effect to my thumbnails. I could use the shadow classes's load, save, etc. but then I have the 'overlay' function from my new class.

So you'd have something like:

PHP:
<?php

require_once 'class.dropshadow.php';

class 
thumbcrop extends dropshadow
{

    function 
crop(...)
    {
        
// ...
    
}

}

?>


Then you just have to create an instance of the 'thumbcrop' class and when you're ready to, use the crop method.

You could rip the important parts out of the cropcanvas class and stick into your extension class.

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


Joined: 29 Mar 2004
Posts: 13

PostPosted: Fri May 28, 2004 5:01 am    Post subject: re: Reply with quote

Embarassed im not into php coding at the moment (although i do understand some of it), more into graphic design, which is why i came to this forum for help (nudge nudge).

Seriously, if you could construct a code for me, I would be very appreciative..


Edit: I'll manage..
Back to top
View user's profile Send private message
amnuts
Site Admin


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

PostPosted: Fri May 28, 2004 5:24 am    Post subject: Re: re: Reply with quote

TheBuggerGuy wrote:
Edit: I'll manage..


You sure? I probably couldn't whip something up until next week, but if you're still needing it then and using the thumbnail and crop canvas seperately aren't doing it for you, then just give us another shout.

Using them together is pretty simply. One example is like this:

PHP:
<?php if (!file_exists($final)) {
                    
$ds->loadImage($origFile);
                    
$ds->resizeToSize(1000);
                    
$ds->saveFinal($final'jpg'80);
                    
$sizes getimagesize($final);
                    if (
$sizes[1] > 75) {
                        
$cc->loadImage($final);
                        
$cc->cropToSize(10075ccCENTRE);
                        
$cc->saveImage($final100);
                        
$cc->flushImages();
                    }
                    
$ds->flushImages();
                    
$ds->loadImage($final);
                    
$ds->applyShadow();
                    
$ds->saveFinal($final'jpg'100);
                } 
?>


But I understand the desire to have it done in one easy package!

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


Joined: 29 Mar 2004
Posts: 13

PostPosted: Fri May 28, 2004 6:01 am    Post subject: Re: re: Reply with quote

amnuts wrote:
TheBuggerGuy wrote:
Edit: I'll manage..


You sure?


... yes....... ok.... no Sad

but there is no need for rush.. just seeing if i can get the best out of these darn good scripts
Back to top
View user's profile Send private message
TheBuggerGuy
Newbie


Joined: 29 Mar 2004
Posts: 13

PostPosted: Sat May 29, 2004 10:54 pm    Post subject: Reply with quote

Okay. I've tried to embed both scripts together to my liking.

Heres what I've managed to conjure up
PHP:
<?php $size getimagesize("./../../{$_GET['input']}"); 
if (
$size[0] > $size[1]) {
        
$cc->loadImage("./../../{$_GET['input']}"); 
        
$cc->cropByPercent(4545ccCENTER); 
        
$cc->saveFinal($final'jpg'80);  
$sizes getimagesize($final); 
if (
$sizes[0] > $sizes[1]) { 
        
$ds->loadImage($final); 
        
$ds->resizeToSize($_GET['maxsize'], 0); 
        } else { 
        
$ds->resizeToSize(0$_GET['maxsize']); 

if (
$_GET['shadow'] == 1) { 
        
$ds->applyShadow($_GET['colour']); 
        
$ds->showShadow('jpg'); 
        } else { 
        
$ds->showFinal('jpg');      
?>


Taken, its very amateur, but here's what I would expect the script to do:
  • Get the image from address
  • Crop 45% of the image both ways
  • Resize to thumbnail size
  • Drop a shadow
  • Display as an image
My idea is right but not my script. By all means, please try and fix my script..
Back to top
View user's profile Send private message
amnuts
Site Admin


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

PostPosted: Mon May 31, 2004 11:23 am    Post subject: Reply with quote

Try something like this:

PHP:
<?php $input  "/your/path/here/{$_GET['input']}";
$output "/your/path/here/output.jpg";

$cc->loadImage($input);
$cc->cropByPercent(4545ccCENTER);
$cc->saveFinal($output'jpg'80); 

$ds->loadImage($output);
$sizes getimagesize($output);
if (
$sizes[0] > $sizes[1]) {
    
$ds->resizeToSize($_GET['maxsize'], 0);
} else {
    
$ds->resizeToSize(0$_GET['maxsize']);
}
if (
$_GET['shadow'] == 1) {
    
$ds->applyShadow($_GET['colour']);
    
$ds->showShadow('jpg');
} else {
    
$ds->showFinal('jpg');      
?>


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


Joined: 29 Mar 2004
Posts: 13

PostPosted: Tue Jun 01, 2004 1:47 am    Post subject: Reply with quote

Quote:
$cc->saveFinal($output, 'jpg', 80);

I dont want to save it.. After it being cropped, I want to drop a shadow then display the image..
(if saving the image is a necessary step, if I had multiple images, wouldn't each overwrite each other [since its the same $output])
Back to top
View user's profile Send private message
amnuts
Site Admin


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

PostPosted: Tue Jun 01, 2004 7:50 am    Post subject: Reply with quote

Saving the image after the crop is an evil neccessity at this stage, unfortuantly. However, you could change the '$output' variable to be whatever you like... Heck! Make it a unique id and then once you've loaded the image into the dropshadow class, just delete the file that was the crop.

PHP:
<?php $input  "/your/path/here/{$_GET['input']}"
$output "/your/path/here/output.jpg"

$tempFile '/tmp/' uniqid('') . '.jpg';

$cc->loadImage($input); 
$cc->cropByPercent(4545ccCENTER); 
$cc->saveFinal($tempFile'jpg'80); 

$ds->loadImage($tempFile); 
unlink($tempFile);
$sizes getimagesize($output); 
if (
$sizes[0] > $sizes[1]) { 
    
$ds->resizeToSize($_GET['maxsize'], 0); 
} else { 
    
$ds->resizeToSize(0$_GET['maxsize']); 

if (
$_GET['shadow'] == 1) { 
    
$ds->applyShadow($_GET['colour']); 
    
$ds->showShadow('jpg'); 
} else { 
    
$ds->showFinal('jpg');       
?>


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


Joined: 29 Mar 2004
Posts: 13

PostPosted: Wed Jun 02, 2004 2:04 am    Post subject: Reply with quote

thanks! i finally got it to work.

for those of you playing at home, here was my final script:
PHP:
<?php $input  "/home/username/public_html/{$_GET['input']}"
$tempFile '/home/username/public_html/tmp/' uniqid('') . '.jpg'

$cc->loadImage($input); 
$cc->cropByPercent(3535ccCENTER); 
$cc->saveImage($tempFile'jpg'90); 

$ds->loadImage($tempFile); 
unlink($tempFile);
$sizes getimagesize($input); 
if (
$sizes[0] > $sizes[1]) { 
    
$ds->resizeToSize($_GET['maxsize'], 0); 
} else { 
    
$ds->resizeToSize(0$_GET['maxsize']); 

if (
$_GET['shadow'] == 1) { 
    
$ds->applyShadow($_GET['colour']); 
    
$ds->showShadow('jpg'); 
} else { 
    
$ds->showFinal('jpg');        
?>
Back to top
View user's profile Send private message
amnuts
Site Admin


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

PostPosted: Wed Jun 02, 2004 2:57 am    Post subject: Reply with quote

TheBuggerGuy wrote:
thanks! i finally got it to work.


*cheers* Very Happy
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 -> Drop Shadowed Thumbnail Creator 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