Php Image cropping

Makkura

New Member
Hi there guys I was wondering if someone could help me with this because I'm like all night trying to figure this out =__=

I'm trying to find how to crop my images without black borders on the side. So basically it should cut some off on the top and the bottom so it stays centered.

I already made a function which resizes the image and that worked out so far but after that I tried adding a cropping function because the image would get squished together.

This is the page i'm talking about. You'll see what I'm talking about.

http://makkura.net76.net/index.php

This was something I tried to crop the image: (yes the pointer points to the image and it works for the resizing function)
(crop_height / crop_width are supplied by arguments)
$new_image = imagecreatetruecolor($crop_width, $crop_height);
$wm = $this->image /$crop_width;
$hm = $this->getHeight() /$crop_height;
$h_height = $crop_height/2;
$w_height = $crop_width/2;

echo "image width is greater than image height";
$adjusted_width =$this->getWidth() / $hm;
$half_width = $adjusted_width / 2;
$int_width = $half_width - $w_height;
imagecopyresampled($new_image ,$this->image ,-$int_width,0,0,0, $adjusted_width, $crop_height, $this->getWidth() , $this->getHeight() );
 
Last edited:

Makkura

New Member
Solved

Solved my own problem.
I resized my image with the width as the only argument, the only thing I had to do then was centering the image and slicing it on the top and the bottom..

so I used imagecopy() to copy a certain piece of the image, leaving out the top and bottom piece.
 
Top