Created
April 13, 2011 20:46
-
-
Save amphibian/918376 to your computer and use it in GitHub Desktop.
Creates internal thumbnails for images uploaded outside of ExpressionEngine. Requires EE 2.1.4 or later.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Change your upload directory ID here. | |
$upload_dir_id = 2; | |
$this->EE =& get_instance(); | |
$this->EE->load->library('filemanager'); | |
$files = $this->EE->filemanager->fetch_files($upload_dir_id); | |
foreach($files->files[$upload_dir_id] as $data) | |
{ | |
$dir = array('server_path' => $data['relative_path']); | |
if($this->EE->filemanager->create_thumb($dir, $data) == TRUE) | |
{ | |
echo('<p style="color: green;">Thumbnail created for <strong>'.$data['short_name'].'</strong>.</p>'); | |
} | |
else | |
{ | |
echo('<p style="color: red;">Trouble creating thumbnail for <strong>'.$data['short_name'].'</strong>.</p>'); | |
} | |
} | |
/* | |
Paste this in a PHP-enabled template and load it up. | |
Will only work in EE 2.1.4 and later. | |
*/ | |
?> |
Sorry to be an newb, but is create_thumb() part of the existing code for EE 2.x? In other words, when I upload a file for a usual EE entry in the Publish or Edit interface is there a way to create a thumbnail?
Thanks,
Bob.
Hey Bob – EE does create thumbnails when you upload a file, and this function in fact just hooks into that process directly. But these are just internal thumbnails for EE's use (showing a preview on the Edit screen after you revisit the entry) -- they're not for using on the front-end of your site. The function actually has the thumbnail size hard-coded.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, that did the trick