I'm developing a custom image upload field in WordPress, but I'm having a ton of difficulty dealing with the image once it's been uploaded. In addition to the upload, I need to resize the image to use a thumbnail. Every time I try to work with the uploaded image, I get an error to do with being unable to find the file (even though I can view it in a browser and it's clearly in the directory). Images are 666 by default when uploaded, but I've also tried manipulating one at 777 with the same results. The resize function is called on its own after the image is uploaded. Here's one of the attempts I made:
function resize_author_picture($filename) {
$filename = $_POST['file'];
$file = fopen($filename, 'r');
$data = fread($file);
fclose($file);
$dimensions = getimagesize($filename);
$dir = dirname($filename);
$crop = wp_crop_image( $data, $dimensions[0], $dimensions[1], 0, 0, 250, 280, null, $dir."/image.jpg" );
die( "crop: ".var_dump($crop)." file: ".$filename." path: ".$dir."/image.jpg" );
}
Here I used fopen() as a second attempt once providing just the image's path didn't work. Here is the previous attempt:
function resize_author_picture($file) {
$file = $_POST['file'];
$dimensions = getimagesize($file);
$dir = dirname($file);
$crop = wp_crop_image( $file, $dimensions[0], $dimensions[1], 0, 0, 250, 280, null, $dir."/image.jpg" );
die( "crop: ".var_dump($crop)." file: ".$file." path: ".$dir."/image.jpg" );
}
Both return a WP error object along these lines:
string(123) "File <http://actionablebooks.jetcooper.local/wp-content/uploads/2010/09/squares-wide.jpeg> doesn't exist?"
Running out of ideas, any input is appreciated!