/**
 * From wp-admin/includes/image-edit.php
 */
function pte_stream_preview_image($post_id)
{
    $post = get_post($post_id);
    @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
    $img = wp_get_image_editor(_load_image_to_edit_path($post_id));
    if (is_wp_error($img)) {
        return false;
    }
    // scale the image
    $size = $img->get_size();
    $w = $size['width'];
    $h = $size['height'];
    $ratio = pte_image_get_preview_ratio($w, $h);
    $w2 = $w * $ratio;
    $h2 = $h * $ratio;
    if (is_wp_error($img->resize($w2, $h2))) {
        return false;
    }
    return wp_stream_image($img, $post->post_mime_type, $post_id);
}
Пример #2
0
 public static function captcha_image()
 {
     $field_properties = array('type' => 'captcha', 'simpleCaptchaSize' => $_GET['size'], 'simpleCaptchaFontColor' => $_GET['fg'], 'simpleCaptchaBackgroundColor' => $_GET['bg']);
     /* @var GF_Field_CAPTCHA $field */
     $field = GF_Fields::create($field_properties);
     if ($_GET['type'] == 'math') {
         $captcha = $field->get_math_captcha($_GET['pos']);
     } else {
         $captcha = $field->get_captcha();
     }
     @ini_set('memory_limit', '256M');
     $image = imagecreatefrompng($captcha['path']);
     include_once ABSPATH . 'wp-admin/includes/image-edit.php';
     wp_stream_image($image, 'image/png', 0);
     imagedestroy($image);
     die;
 }
Пример #3
0
/**
 * Streams image in post to browser, along with enqueued changes
 * in $_REQUEST['history']
 *
 * @param int $post_id
 * @return boolean
 */
function stream_preview_image($post_id)
{
    $post = get_post($post_id);
    /** This filter is documented in wp-admin/admin.php */
    @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
    $img = wp_get_image_editor(_load_image_to_edit_path($post_id));
    if (is_wp_error($img)) {
        return false;
    }
    $changes = !empty($_REQUEST['history']) ? json_decode(wp_unslash($_REQUEST['history'])) : null;
    if ($changes) {
        $img = image_edit_apply_changes($img, $changes);
    }
    // Scale the image.
    $size = $img->get_size();
    $w = $size['width'];
    $h = $size['height'];
    $ratio = _image_get_preview_ratio($w, $h);
    $w2 = max(1, $w * $ratio);
    $h2 = max(1, $h * $ratio);
    if (is_wp_error($img->resize($w2, $h2))) {
        return false;
    }
    return wp_stream_image($img, $post->post_mime_type, $post_id);
}
Пример #4
0
function stream_preview_image($post_id)
{
    $post = get_post($post_id);
    @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
    $img = load_image_to_edit($post_id, $post->post_mime_type, array(400, 400));
    if (!is_resource($img)) {
        return false;
    }
    $changes = !empty($_REQUEST['history']) ? json_decode(stripslashes($_REQUEST['history'])) : null;
    if ($changes) {
        $img = image_edit_apply_changes($img, $changes);
    }
    // scale the image
    $w = imagesx($img);
    $h = imagesy($img);
    $ratio = _image_get_preview_ratio($w, $h);
    $w2 = $w * $ratio;
    $h2 = $h * $ratio;
    $preview = wp_imagecreatetruecolor($w2, $h2);
    imagecopyresampled($preview, $img, 0, 0, 0, 0, $w2, $h2, $w, $h);
    wp_stream_image($preview, $post->post_mime_type, $post_id);
    imagedestroy($preview);
    imagedestroy($img);
    return true;
}
 public static function captcha_image()
 {
     $field = array("simpleCaptchaSize" => $_GET["size"], "simpleCaptchaFontColor" => $_GET["fg"], "simpleCaptchaBackgroundColor" => $_GET["bg"]);
     if ($_GET["type"] == "math") {
         $captcha = GFCommon::get_math_captcha($field, $_GET["pos"]);
     } else {
         $captcha = GFCommon::get_captcha($field);
     }
     @ini_set('memory_limit', '256M');
     $image = imagecreatefrompng($captcha["path"]);
     include_once ABSPATH . 'wp-admin/includes/image-edit.php';
     wp_stream_image($image, "image/png", 0);
     imagedestroy($image);
     die;
 }
Пример #6
0
/**
 * Streams image in post to browser, along with enqueued changes
 * in $_REQUEST['history']
 *
 * @param int $post_id
 * @return boolean
 */
function stream_preview_image($post_id)
{
    $post = get_post($post_id);
    @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
    $img = WP_Image_Editor::get_instance(_load_image_to_edit_path($post_id));
    if (is_wp_error($img)) {
        return false;
    }
    $changes = !empty($_REQUEST['history']) ? json_decode(stripslashes($_REQUEST['history'])) : null;
    if ($changes) {
        $img = image_edit_apply_changes($img, $changes);
    }
    // scale the image
    $size = $img->get_size();
    $w = $size['width'];
    $h = $size['height'];
    $ratio = _image_get_preview_ratio($w, $h);
    $w2 = $w * $ratio;
    $h2 = $h * $ratio;
    if (is_wp_error($img->resize($w2, $h2))) {
        return false;
    }
    return wp_stream_image($img, $post->post_mime_type, $post_id);
}
Пример #7
0
/**
 * Streams image in post to browser, along with enqueued changes
 * in $_REQUEST['history']
 *
 * @param int $post_id
 * @return bool
 */
function stream_preview_image($post_id)
{
    $post = get_post($post_id);
    wp_raise_memory_limit('admin');
    $img = wp_get_image_editor(_load_image_to_edit_path($post_id));
    if (is_wp_error($img)) {
        return false;
    }
    $changes = !empty($_REQUEST['history']) ? json_decode(wp_unslash($_REQUEST['history'])) : null;
    if ($changes) {
        $img = image_edit_apply_changes($img, $changes);
    }
    // Scale the image.
    $size = $img->get_size();
    $w = $size['width'];
    $h = $size['height'];
    $ratio = _image_get_preview_ratio($w, $h);
    $w2 = max(1, $w * $ratio);
    $h2 = max(1, $h * $ratio);
    if (is_wp_error($img->resize($w2, $h2))) {
        return false;
    }
    return wp_stream_image($img, $post->post_mime_type, $post_id);
}