TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 10-05-2009, 08:42 AM   #1 (permalink)
The Wanderer
 
Join Date: Oct 2009
Posts: 5
Thanks: 0
TheCheshiereCat is on a distinguished road
Default Cropping In PHP

Hello everyone

I stumbled upon <a href=http://www.talkphp.com/advanced-php-programming/1709-cropping-images-using-php.html>this great tutorial</a> on how to crop images using PHP.

I created a page called thumbCreate.php containing the following code from the tutorial:

PHP Code:
<?php
class cropImage{
    var 
$imgSrc,$myImage,$cropHeight,$cropWidth,$x,$y,$thumb;
}

function 
setImage($image)
{

//Your Image
   
$this->imgSrc $image
                     
//getting the image dimensions
   
list($width$height) = getimagesize($this->imgSrc); 
                     
//create image from the jpeg
   
this->myImage imagecreatefromjpeg($this->imgSrc) or die("Error: Cannot find image!"); 
            
       if(
$width $height$biggestSide $width//find biggest length
       
else $biggestSide $height
                     
//The crop size will be half that of the largest side 
   
$cropPercent .5// This will zoom in to 50% zoom (crop)
   
$this->cropWidth   $biggestSide*$cropPercent
   
$this->cropHeight  $biggestSide*$cropPercent
                     
                     
//getting the top left coordinate
   
$this->= ($width-$this->cropWidth)/2;
   
$this->= ($height-$this->cropHeight)/2;
             
}  

function 
createThumb()
{
                    
  
$thumbSize 250// will create a 250 x 250 thumb
  
$this->thumb imagecreatetruecolor($thumbSize$thumbSize); 

  
imagecopyresampled($this->thumb$this->myImage00,$this->x$this->y$thumbSize$thumbSize$this->cropWidth$this->cropHeight); 


function 
renderImage()
{
                     
   
header('Content-type: image/jpeg');
   
imagejpeg($this->thumb);
   
imagedestroy($this->thumb); 
}  

    
$image = new cropImage;
    
$image->setImage($src);
    
$image->createThumb();
    
$image->renderImage();

?>
I then wrote this in another php page:

PHP Code:
                                <img src='createThumb.php?src=gallery/1.jpg' border='0' alt=".$picture[0]."

However, the image will not show, even though I definitely do have an image stored at gallery/1.jpg.

Although I'm familiar with OOP programming in Java, this is my first time trying it with PHP, so perhaps my syntax is wrong.

Any help would be greatly appreciated.

THANKS in advance!
Tom
TheCheshiereCat is offline  
Reply With Quote
The Following User Says Thank You to TheCheshiereCat For This Useful Post:
Y.P.Y (10-09-2009)
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't get PHP 5. to work? Newbie windows PHP guy DotNetTim Absolute Beginners 11 02-01-2013 11:02 AM
Cropping Images using PHP Rendair Advanced PHP Programming 22 05-17-2012 10:22 AM
10 PHP Myths Dispelled Wildhoney General 9 06-15-2009 06:55 AM
PHP Compressor Kalle Script Giveaway 8 05-28-2008 12:14 AM
what are all the subjects in php? sarmenhb General 7 01-21-2008 05:41 PM


All times are GMT. The time now is 12:37 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design