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 and shadow: poor quality output
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
guildford
Newbie


Joined: 10 Jun 2004
Posts: 12
Location: Melbourne, Australia

PostPosted: Fri Jun 11, 2004 3:18 am    Post subject: crop and shadow: poor quality output Reply with quote

im encountering some problems.

here is my current script:

PHP:
<?php

// address style: script.php?input=pic.jpg&shadow=1&bg=#AA&size=100

require 'class.cropcanvas.php';
$cc = new canvasCrop();
require_once 
"class.dropshadow.php"
$ds = new dropShadow(FALSE); 
$ds->setShadowPath('./'); 

$input  "/home/user/public_html/{$_GET['input']}"
$tempFile '/home/user/public_html/tmp/' uniqid('') . '.jpg'

$cc->loadImage($input); 
$cc->cropToSize('200''200'ccTOPLEFT);
$cc->saveImage($tempFile'jpg'90); 

$ds->loadImage($tempFile); 
unlink($tempFile);  

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


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


  • The images are turning out of very poor quality (ive tested and the cropping part outputs good quality but after the dropshadow, the quality turns bad)
  • Secondly, is there a way to subsitute the ccTOPLEFT for the address bar? (ie: script.php?area=topleft)


i have GD 2 so i dont see a problem there
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 Jun 11, 2004 3:28 am    Post subject: Re: crop and shadow: poor quality output Reply with quote

guildford wrote:
The images are turning out of very poor quality (ive tested and the cropping part outputs good quality but after the dropshadow, the quality turns bad)


Try playing around with the quality you're saving the image as. Right now you're saving the crop as 90% quality, and then you're saving the resized image as 90% quality of the already 90% quality file... Make sense? So either save your crop as 100%, or save the resized one as 100%.

Incidently, you may want to consider resizing the image, then cropping, then adding a shadow. For example, what happens if you use the script to resize a big picture of the landscape? Your thumbnail will most likely end up being the sky, rather than have any of the landscape in it. Sure, it'd be a couple more steps to take, but it's not that big a leap from what you have now.

guildford wrote:
Secondly, is there a way to subsitute the ccTOPLEFT for the address bar? (ie: script.php?area=topleft)


Why not just use the enumerated value of ccTOPLEFT? Do you see these lines at the top of the class?

define("ccTOPLEFT", 0);
define("ccTOP", 1);
define("ccTOPRIGHT", 2);
define("ccLEFT", 3);
define("ccCENTRE", 4);
define("ccCENTER", 4);
define("ccRIGHT", 5);
define("ccBOTTOMLEFT", 6);
define("ccBOTTOM", 7);
define("ccBOTTOMRIGHT", Cool;

Well, every time you use ccTOPLEFT you're actually just using an alias for the number 0. If you used ccBOTTOM you're just telling the script to use the number 7. So in your query string you could have:

script.php?area=0

and then you could use:

$cc->cropToSize('200', '200', $_GET['area']);

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


Joined: 10 Jun 2004
Posts: 12
Location: Melbourne, Australia

PostPosted: Fri Jun 11, 2004 3:37 am    Post subject: Reply with quote

does it have to be a number .. id prefer writing area=topleft than area=0
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 Jun 11, 2004 3:42 am    Post subject: Reply with quote

If you want to do that then you'll have to update your script somewhere to include what the value of the string is. For example, you could do something like:

PHP:
<?php

    $strVals 
= array(
        
'topleft'   => ccTOPLEFT,
        
'top'       => ccTOP,
        
'topright' => ccTOPRIGHT,
        
// and so on
    
);

    
// when you come to cropping you'd then do:

    
$cc->cropToSize('200''200'$strVals[$_GET['area']]);

?>


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


Joined: 10 Jun 2004
Posts: 12
Location: Melbourne, Australia

PostPosted: Fri Jun 11, 2004 3:53 am    Post subject: Reply with quote

great! but theres still the problem with the quality. even with both parameters set to 100, i get an output of something like 40.. :/

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 Jun 11, 2004 4:03 am    Post subject: Reply with quote

Hmm... That really is quite poor quality. However, you mentioned that you viewed just the crop result and it seemed fine, right? So the problem lays with creating the thumbnail.

Try this... Rather than save as a JPG file from your crop, save as a PNG. Then have the dropshadow class load up that PNG and try to show the image with a 90% quality to start with, working up from there. See if that makes a difference.

This is odd because I used the same technique and I get no problems. I'm using the bundled GD version with PHP, which is something around 2.0.15. Are you using the bundled version or a pre-compiled GD 2.x?

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


Joined: 10 Jun 2004
Posts: 12
Location: Melbourne, Australia

PostPosted: Fri Jun 11, 2004 4:07 am    Post subject: Reply with quote

i was just thinking that.. the png issue worked and everything is working as planned.

thanks a lot andy!
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 Jun 11, 2004 4:20 am    Post subject: Reply with quote

Cool! No probs Smile
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
guildford
Newbie


Joined: 10 Jun 2004
Posts: 12
Location: Melbourne, Australia

PostPosted: Fri Jun 11, 2004 4:30 am    Post subject: Reply with quote

this question has been nudging me at the back of my mind and I have to ask it before it actually happens.

I crop at 200x200 right? What if the image is smaller than 200 wide or 200 high?

Now I would guess that it would crop normally and leave black background where nothing is present.. but the script thinks otherwise..

Is there a way around this? I dont want to supply a seperate crop size for each image..
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 Jun 11, 2004 5:11 am    Post subject: Reply with quote

If the cavas is smaller than the request crop size then it will not do anything. If you wanted to get around this behaviour then you'd have to edit the class (or write an extension class which overrides the fuction the check it in) to remove the check and/or do other processing (like creating an image to the correct dimensions, setting the background colour to be black, then copying the cropped part of your image to it).

However, in your instance there may be a way to avoid that. You are cropping and then resizing, right? Why not check the image size first and if it's width or height is less than 200px resize it up so that the minimum size is 200px. Then crop that image. That's also another reasonm why you might like to do the resizing first, because you can make sure that the thumnail size has the correct minimum dimensions for the crop you want (as well as getting more info on screen). Of course, you application might dictate that you need to crop first...

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


Joined: 10 Jun 2004
Posts: 12
Location: Melbourne, Australia

PostPosted: Fri Jun 11, 2004 5:41 am    Post subject: Reply with quote

okay, but the dropshadow's saveFinal isnt working for some reason.. the whole script stops after it has resized and the cropper says [cannot load filename '' ] (wheres the filename?)

PHP:
<?php

require 'thumbnail/class.cropcanvas.php';
$cc = new canvasCrop(FALSE);
require_once 
"thumbnail/class.dropshadow.php"
$ds = new dropShadow(FALSE); 
$ds->setShadowPath('./thumbnail/'); 

$input  "/home/user/public_html/{$_GET['input']}"
$tempFile '/home/user/public_html/tmp/' uniqid('') . '.png'

$ds->loadImage($input); 
$sizes getimagesize($input); 
if (
$sizes[0] > $sizes[1]) { 
    
$ds->resizeToSize(2100); 
} else { 
    
$ds->resizeToSize(0210); 
}

$ds->saveFinal($tempFile'png'); 

$cc->loadImage($tempfile); 
$cc->cropToSize('200''200'ccTOP);
$cc->saveImage($tempFile'png');

$ds->loadImage($tempFile); 
if (
$_GET['shadow'] == 1) { 
    
$ds->applyShadow($_GET['bg']); 
    
$ds->showShadow('jpg'); 
} else { 
    
$ds->showFinal('jpg'90);         
}
?>
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 Jun 11, 2004 6:15 am    Post subject: Reply with quote

$cc->loadImage($tempfile);

should be:

$cc->loadImage($tempFile);

Also, you may want to flush the images in the dropshadow class, because you're using the same object and so the resized file will still be in teh class variables. So have something like:

...
$cc->saveImage($tempFile, 'png');
$ds->flushImages();
$ds->loadImage($tempFile);
...

Oh, and don't forget to unlink the tempFile when you're done, els eyou'll get a mighty fine collection of images you probably don't want! 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
guildford
Newbie


Joined: 10 Jun 2004
Posts: 12
Location: Melbourne, Australia

PostPosted: Sun Jun 13, 2004 9:20 pm    Post subject: Reply with quote

Quote:
Debug message from function resizeToSize: Image size is 210 / 157.5

Error in function cropToSize: The image could not be cropped because the size given is larger than the original image.


Question

.....

I think the problem is with the resize:
PHP:
<?php $sizes getimagesize($input); 
if (
$sizes[0] > $sizes[1]) { 
    
$ds->resizeToSize(2100); 
} else { 
    
$ds->resizeToSize(0210); 
?>

I think we need to change it so that the script reszies to at least 200 wide and 200 high, so the crop can kick in..
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 Jun 14, 2004 3:14 am    Post subject: Reply with quote

All you really need to do is flip around where you're sending the 210 parameter. Right now you're checking to see if width is greater than height. If it is then you're resizing the width to 210 and the height to be proportional, so the height is always going to be smaller. To perform the crop you want to resize the smallest dimension to 210 so that you'll always have overhang on the size. Such as:

PHP:
<?php $sizes getimagesize($input); 
if (
$sizes[0] > $sizes[1]) { 
    
$ds->resizeToSize(0210); 
} else { 
    
$ds->resizeToSize(2100); 
?>


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


Joined: 10 Jun 2004
Posts: 12
Location: Melbourne, Australia

PostPosted: Mon Jun 14, 2004 5:35 am    Post subject: more problems.. Reply with quote

okay... now the cropper doesnt seem to respond. debug messages for crop arent showing up at all.

the crop script seems undoubtibly not working
the result im getting now is a resized image, and a shadow.. the crop did not work at all..

PHP:
<?php

require 'thumbnail/class.cropcanvas.php';
$cc = new canvasCrop(FALSE);
require_once 
"thumbnail/class.dropshadow.php"
$ds = new dropShadow(FALSE); 
$ds->setShadowPath('./thumbnail/'); 

$input  "/home/user/public_html/{$_GET['input']}"
$tempFile '/home/user/public_html/tmp/' uniqid('') . '.png'

$ds->loadImage($input); 
$sizes getimagesize($input); 
if (
$sizes[0] > $sizes[1]) { 
    
$ds->resizeToSize(0210); 
} else { 
    
$ds->resizeToSize(2100); 
}
$ds->saveFinal($tempFile'png'); 

$cc->loadImage($tempFile); 
$cc->cropToSize('200''200'ccTOP);
$cc->saveImage($tempFile'png');

$ds->loadImage($tempFile); 
if (
$_GET['shadow'] == 1) { 
    
$ds->applyShadow($_GET['bg']); 
    
$ds->showShadow('jpg'); 
} else { 
    
$ds->showFinal('jpg'90);         
}
?>
Back to top
View user's profile Send private message
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