<commit_before><?php

//TO USE 
// - configure settings in includes/config.inc
// - optional: customize handle_authorization() and store_meta() in includes/fileupload_page_logic.inc

require_once 'includes/config.inc';


//This should set up the standard page variables and page logic
//Calls the PageMain() function in this file if there's no preemtive redirect or error.
require_once 'includes/fileupload_page_logic.inc';


function PageMain()
{
    global $config;



    if ( !isset( $_FILES['fileupload'] ) )
    {
        echo '{"error":"no file"}';
        return;
    }


    $valid_types = $config[$config['env']]['fileupload_valid_types'];
    $img_types = array("jpg", "jpeg", "gif", "png");
    $file_extension = strtolower( pathinfo( $_FILES['fileupload']['name'], PATHINFO_EXTENSION ) );
    if ( !in_array( $file_extension, $valid_types ) )
    {
        echo '{"error":"invalid type"}';
        return;
    }

    if ( in_array( $file_extension, $img_types ) && (intval( postVar('resize_width')) >0  || intval( postVar('resize_height')) > 0) ) {
        try {
            $orig = imagecreatefromstring(file_get_contents($_FILES['fileupload']['tmp_name']));
            $ox = imagesx( $orig );
            $oy = imagesy( $orig );
            $newx = intval( postVar('resize_width') );
            $newy = intval( postVar('resize_height') );

            if ( !isset( $newx ) || $newx == "" || intval( $newx ) <= 0 ) {
                $newx = $newy * $ox / $oy;
            }
            if ( !isset( $newy ) || $newy == "" || intval( $newy ) <= 0 ) {
                $newy = $newx * $oy / $ox;
            }

            $maxdimension = $config[$config['env']]['fileupload_max_img_dimension'];
            $newx = ($newx > $maxdimension )? $maxdimension: $newx;
            $newy = ($newy > $maxdimension)? $maxdimension: $newy;
            $oldr = $ox / $oy;
            $newr = $newx / $newy;<commit_msg>resize calculations now return whole numbers<commit_after><?php

//TO USE 
// - configure settings in includes/config.inc
// - optional: customize handle_authorization() and store_meta() in includes/fileupload_page_logic.inc

require_once 'includes/config.inc';
require_once 'includes/common.inc';


//This should set up the standard page variables and page logic
//Calls the PageMain() function in this file if there's no preemtive redirect or error.
require_once 'includes/fileupload_page_logic.inc';


function PageMain()
{
    global $config;



    if ( !isset( $_FILES['fileupload'] ) )
    {
        echo '{"error":"no file"}';
        return;
    }


    $valid_types = $config[$config['env']]['fileupload_valid_types'];
    $img_types = array("jpg", "jpeg", "gif", "png");
    $file_extension = strtolower( pathinfo( $_FILES['fileupload']['name'], PATHINFO_EXTENSION ) );
    if ( !in_array( $file_extension, $valid_types ) )
    {
        echo '{"error":"invalid type"}';
        return;
    }

    if ( in_array( $file_extension, $img_types ) && (intval( postVar('resize_width')) >0  || intval( postVar('resize_height')) > 0) ) {
        try {
            $orig = imagecreatefromstring(file_get_contents($_FILES['fileupload']['tmp_name']));
            $ox = imagesx( $orig );
            $oy = imagesy( $orig );
            $newx = intval( postVar('resize_width') );
            $newy = intval( postVar('resize_height') );

            if ( !isset( $newx ) || $newx == "" || intval( $newx ) <= 0 ) {
                $newx = intval( $newy * $ox / $oy );
            }
            if ( !isset( $newy ) || $newy == "" || intval( $newy ) <= 0 ) {
                $newy = intval( $newx * $oy / $ox );
            }

            $maxdimension = $config[$config['env']]['fileupload_max_img_dimension'];
            $newx = ($newx > $maxdimension )? $maxdimension: $newx;
            $newy = ($newy > $maxdimension)? $maxdimension: $newy;
            $oldr = $ox / $oy;
            $newr = $newx / $newy;
{'fraction_non_alphanumeric': 0.16670908628149655, 'fraction_numerical': 0.0020361415118350726, 'mean_word_length': 2.6055045871559632, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '864387', 'n_tokens_mistral': 1297, 'n_tokens_neox': 1237, 'n_words': 286}