Jump to content

Resizing images comes up with a yellow issue


TeddyKiller

Recommended Posts

I did an if statement. I dont need pixel sizes now. It'll automatically square the image no matter on the size in the center. I believe it's a masterpiece.

 

It may or may not work.. I haven't tested it so far. Here's the code

<?php
// Original image
$filename = '20070107-ces-billgates-400.jpg';
// cropped image name
$filename2 = 'c_' . $filename;
// Get dimensions of the original image
list($current_width, $current_height) = getimagesize($filename);

// This will be the final size of the image (e.g. how many pixels left and down we will be going)
if($current_width > $current_height){
$crop_width = $current_height;
$crop_height = $current_height;
}
elseif($current_height > $current_width){
$crop_width = $current_width;
$crop_height = $current_width;
)

// The x and y coordinates on the original image where we will begin cropping the image
$sum1 = $current_width - $crop_width;
$left = $sum1 / 2;

$sum2 = $current_height - $height;
$top = $sum2 / 2;

// Resample the image
$canvas = imagecreatetruecolor($crop_width, $crop_height);
$current_image = imagecreatefromjpeg($filename);
imagecopy($canvas, $current_image, 0, 0, $left, $top, $current_width, $current_height);
imagejpeg($canvas, $filename2, 100);
?> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.