I have a script that crops the image from the center, is there any way to make it crop from top of the image? I tried to do it, but I just messed up the code.
Here is the script for the cropping:
if($crop){
$new_image = imagecreatetruecolor($width, $height);
if($current_ratio > $desired_ratio_after){
$new_width = $old_width * $height / $old_height;
}
if($current_ratio > $desired_ratio_before && $current_ratio < $desired_ratio_after){
if( $old_width > $old_height ){
$new_height = max( $width, $height );
$new_width = $old_width * $new_height / $old_height;
}
else{
$new_height = $old_height * $width / $old_width;
}
}
if($current_ratio < $desired_ratio_before){
$new_height = $old_height * $width / $old_width;
}
$width_ratio = $old_width / $new_width;
$height_ratio = $old_height / $new_height;
$src_x = floor( ( ( $new_width - $width ) / 2 ) * $width_ratio );
$src_y = round( ( ( $new_height - $height ) / 2 ) * $height_ratio );
}
Aucun commentaire:
Enregistrer un commentaire