Code: Select all
// If we have an uploaded image without errors
if (!empty($_FILES) && isset($_FILES['homeimage'])) {
// Resize
foreach ($widths as $key => $width) {
$pathinfo = pathinfo($_FILES['homeimage']['name']);
// Open the uploaded image with the Imagine library
$image = $imagine->open($_FILES['homeimage']['tmp_name']);
// Get image size
$box = $image->getSize();
$ratio = $width / $box->getWidth();
$scaled_box = $box->scale($ratio);
$new_filename = "{$random}_{$pathinfo['filename']}_{$key}.{$pathinfo['extension']}";
$image->resize($scaled_box)->save($target_directory . '/' . $new_filename, array('jpeg_quality' => 100));
}
}