Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Doubt you still need an answer, as this question is quite old, but here it is for future reference:</p> <p>The error your getting is a return of <code>wp_load_image</code> which is used by <code>wp_crop_image</code>. <code>wp_load_image</code> uses the php function <code>file_exists</code>, which needs to be fed the file's path without the domain.</p> <p>So</p> <pre><code>$crop = wp_crop_image( $file, $dimensions[0], $dimensions[1], 0, 0, 250, 280, null, "wp-content/uploads/2010/09/squares-wide.jpeg" ); </code></pre> <p>would have worked.</p> <p>An aside <code>wp_upload_bits</code> does not only upload the file(s) for you it also returns the URL of the uploaded file.</p> <p>If you call <code>wp_upload_bits</code> like so (where "file" is the name of the form's input):</p> <pre><code>if ($_FILES["file"]["name"]!="") { $uploaded_file = wp_upload_bits($_FILES["file"]["name"], null, file_get_contents($_FILES["file"]["tmp_name"])); } </code></pre> <p>Hence <code>$uploaded_file['url']</code> is equivalent to <code>$dir."/image.jpg"</code>. In the above crop, you could have used a substring of <code>$uploaded_file['url']</code>.</p> <p><strong>Concrete example:</strong></p> <p>With <code>http://site.local/wp-content/uploads/2010/09/squares-wide.jpeg</code> this will work:</p> <pre><code>$dir = dirname($file); $dir_substr = substr($dir, 18) $crop = wp_crop_image( $file, $dimensions[0], $dimensions[1], 0, 0, 250, 280, null, $dir."/squares-wide.jpeg" ); </code></pre> <p>Of course you also want the filename to be dynamic, so I'd call <code>wp_uload_bits</code> as proposed above (if it's not coming from a form field, but a WP Custom field call it as you are doing now, the important part is <code>$uploaded_file = wp_upload_bits(...)</code> to save the return of <code>wp_upload_bits</code> in a variable for later use) and then do</p> <pre><code>$file_uri = substr($uploaded_file['url'], 18); $crop = wp_crop_image( $file, $dimensions[0], $dimensions[1], 0, 0, 250, 280, null, $file_uri ); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload