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. | |
*/ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.