Exemple #1
0
function scale_image($res_src_image, $int_new_width, $int_new_height)
{
    $int_orig_width = $int_new_width;
    $int_orig_height = $int_new_height;
    if (imagesx($res_src_image) < imagesy($res_src_image)) {
        // Height Larger Then Width
        // Get New Width
        $int_width_diff = $int_new_width - imagesx($res_src_image);
        $int_new_width = imagesx($res_src_image) + $int_width_diff;
        // Get New Height
        $int_new_height = get_image_height($res_src_image, $int_new_width);
        $res_dst_image = imagecreatetruecolor($int_new_width, $int_new_height);
        imagecopyresampled($res_dst_image, $res_src_image, 0, 0, 0, 0, $int_new_width, $int_new_height, imagesx($res_src_image), imagesy($res_src_image));
    } else {
        // Width Larger Then Height or Equal
        // Get New Height
        $int_height_diff = $int_new_height - imagesy($res_src_image);
        $int_new_height = imagesy($res_src_image) + $int_height_diff;
        // Get New Width
        $int_new_width = get_image_width($res_src_image, $int_new_height);
        $res_dst_image = imagecreatetruecolor($int_new_width, $int_new_height);
        imagecopyresampled($res_dst_image, $res_src_image, 0, 0, 0, 0, $int_new_width, $int_new_height, imagesx($res_src_image), imagesy($res_src_image));
    }
    return $res_dst_image;
}
function get_image_by_template($template = '', $before = '', $after = '')
{
    if ($template == '' || $template == 'default') {
        $template = '<img width="%IMAGE_WIDTH%" height="%IMAGE_HEIGHT%" id="%IMAGE_ID%" src="%IMAGE_URL%" alt="%IMAGE_FILENAME%" />';
    }
    $template = $before . $template . $after;
    $patterns = array('IMAGE_ID' => get_image_id(), 'IMAGE_REAL_ID' => get_image_real_id(), 'IMAGE_FILENAME' => get_image_filename(), 'IMAGE_URL' => get_image_url(), 'IMAGE_VIEWER' => get_image_viewer(), 'IMAGE_SHORTURL' => get_image_shorturl(), 'IMAGE_WIDTH' => get_image_width(), 'IMAGE_HEIGHT' => get_image_height(), 'IMAGE_SIZE' => get_image_size(), 'IMAGE_SIZE_BYTES' => get_image_size_bytes(), 'IMAGE_THUMB_WIDTH' => get_image_thumb_width(), 'IMAGE_THUMB_HEIGHT' => get_image_thumb_height(), 'IMAGE_THUMB_URL' => get_image_thumb_url());
    return preg_replace('/%([a-z_]+)%/ie', '$patterns["$1"]', $template);
}