Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Looking for work? Have a job and looking for that right person to fill your position? Post your resumes and open positions here! Does your company provide a service that the industry needs? Post your service here. Video Editing, blog writing, encoding, programming, the works.

 
Thread Tools
Old 02-01-2013, 08:50 AM   #1
Zeiss
Confirmed User
 
Industry Role:
Join Date: May 2012
Location: With your mom
Posts: 5,189
php image resizer to image cropper

Can you help me transofrm this? I wanna make it crop from center of image, not to resize it to fit a box. Original image must also be kept, should image regeneration be required later on.

PHP Code:
<?php if ( ! defined('ABS_PATH')) exit('ABS_PATH is not loaded. Direct access is not allowed.');

    class 
ImageResizer {

        public static function 
fromFile($imagePath) {
            return new 
ImageResizer($imagePath);
        }

        private 
$im;

        private function 
__construct($imagePath) {
            if(!
file_exists($imagePath)) throw new Exception("$imagePath does not exist!");
            if(!
is_readable($imagePath)) throw new Exception("$imagePath is not readable!");
            if(
filesize($imagePath)==0) throw new Exception("$imagePath is corrupt or broken!");

            if(
osc_use_imagick()) {
                
$this->im = new Imagick($imagePath);                
            } else {
                
$content file_get_contents($imagePath);
                
$this->im imagecreatefromstring($content);
            }

            return 
$this;
        }

        public function 
__destruct() {
            if(
osc_use_imagick()) {
                
$this->im->destroy();
            } else {
                
imagedestroy($this->im);
            }
        }

        public function 
resizeTo($width$height) {
            if(
osc_use_imagick()) {
                
$bg = new Imagick();
                
$bg->newImage($width$height'#FF7F26');
                
                
$this->im->thumbnailImage($width$heighttrue);
                
$geometry $this->im->getImageGeometry();

                
$x = ( $width $geometry['width'] ) / 2;
                
$y = ( $height $geometry['height'] ) / 2;

                
$bg->compositeImage$this->imimagick::COMPOSITE_OVER$x$y );
                
$this->im $bg;
            } else {
                
$w imagesx($this->im);
                
$h imagesy($this->im);

                if((
$w/$h)>=($width/$height)) {
                    
//$newW = $width;
                    
$newW = ($w $width)? $width $w;
                    
$newH $h * ($newW $w);
                } else {
                    
//$newH = $height;
                    
$newH = ($h $height)? $height $h;
                    
$newW $w * ($newH $h);
                }

                
$newIm imagecreatetruecolor($width,$height);//$newW, $newH);
                
imagealphablending($newImfalse);
                
$colorTransparent imagecolorallocatealpha($newIm255255255127);
                
imagefill($newIm00$colorTransparent);
                
imagesavealpha($newImtrue);
                
imagecopyresampled($newIm$this->im, (($width-$newW)/2), (($height-$newH)/2), 00$newW$newH$w$h);
                
imagedestroy($this->im);

                
$this->im $newIm;
            }
            return 
$this;
        }

        public function 
saveToFile($imagePath) {
            if(
file_exists($imagePath) && !is_writable($imagePath)) throw new Exception("$imagePath is not writable!");
            if(
osc_use_imagick()) {
                
$this->im->setImageFileName($imagePath);
                
$this->im->writeImage($imagePath);
            } else {
               
imagejpeg($this->im$imagePath);
            }
        }

        public function 
show() {
            
header('Content-Disposition: Attachment;filename=image.jpg');
            
header('Content-type: image/jpg');
            if(
osc_use_imagick()) {
            } else {
                
imagepng($this->im);
            }
        }

    }

?>
__________________


Adult Webmasters Guides
Zeiss is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-02-2013, 07:43 AM   #2
woj
<&(©¿©)&>
 
woj's Avatar
 
Industry Role:
Join Date: Jul 2002
Location: Chicago
Posts: 47,883
If you want to invest a few bucks, icq: 33375924 or email me at: woj#at#wojfun#.#com
__________________
Custom Software Development, email: woj#at#wojfun#.#com to discuss details or skype: wojl2000 or gchat: wojfun or telegram: wojl2000
Affiliate program tools: Hosted Galleries Manager Banner Manager Video Manager
Wordpress Affiliate Plugin Pic/Movie of the Day Fansign Generator Zip Manager
woj is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-02-2013, 11:32 AM   #3
Itchy
Datetronix.com
 
Itchy's Avatar
 
Industry Role:
Join Date: Jan 2001
Location: Chill-A-Wack BC
Posts: 6,524
http://stackoverflow.com/questions/6...rom-center-php
__________________


ICQ: 2588560
Skype: Pornocop

Itchy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.