I wrote this function in my functions.php
function header_resized_img ($path, $width, $height) {
$image = wp_get_image_editor($path);
if (!is_wp_error($image)) {
$image->resize(9999, $height, false);
$orig_size = $image->get_size();
$image->crop($orig_size['width']/2-$width/2, $orig_size['height']/2-$height/2, $width, $height);
$image->stream( $mime_type = 'image/jpeg');
}
}
To make it work, i created a file named page-image.php, then a page with permalink http://www.example.com/image/. Inside page-image.php i've put (just a test)
header_resized_img (get_header_image(), 414, 700);
which, in facts, does output the resized/cropped image when i visit it. Now i want to make it more flexible and pass parameters through URL. I tried query strings using $_GET
, then i found get_query_arg
, but none of these seems to do the trick. How could i do this? Thank you.