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);
?> 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.