public function generateImage($object, $field, $instance, $bundle)
 {
     $object_field = array();
     static $available_images = array();
     if (empty($available_images)) {
         $available_images = $this->getImages();
     }
     if (empty($available_images)) {
         $args = func_get_args();
         return call_user_func_array('_image_devel_generate', $args);
     }
     $extension = array_rand(array('jpg' => 'jpg', 'png' => 'png'));
     $min_resolution = empty($instance['settings']['min_resolution']) ? '100x100' : $instance['settings']['min_resolution'];
     $max_resolution = empty($instance['settings']['max_resolution']) ? '600x600' : $instance['settings']['max_resolution'];
     if (FALSE === ($tmp_file = drupal_tempnam('temporary://', 'imagefield_'))) {
         return FALSE;
     }
     $destination = $tmp_file . '.' . $extension;
     file_unmanaged_move($tmp_file, $destination, FILE_EXISTS_REPLACE);
     $rand_file = array_rand($available_images);
     if (!empty($instance['settings']['file_directory'])) {
         $instance['settings']['file_directory'] = $instance['settings']['file_directory'] . '/';
     }
     $destination_dir = $field['settings']['uri_scheme'] . '://' . $instance['settings']['file_directory'];
     file_prepare_directory($destination_dir, FILE_CREATE_DIRECTORY);
     if ($this->settings['devel_image_no_alter']) {
         $file = $available_images[$rand_file];
         $file = file_copy($file, $destination_dir);
     } else {
         $image = image_load($rand_file);
         $min = explode('x', $min_resolution);
         $max = explode('x', $max_resolution);
         $max[0] = $max[0] < $min[0] ? $min[0] : $max[0];
         $max[1] = $max[1] < $min[1] ? $min[1] : $max[1];
         $width = rand((int) $min[0], (int) $max[0]);
         $height = rand((int) $min[1], (int) $max[1]);
         if (!image_scale_and_crop($image, $width, $height)) {
             return FALSE;
         }
         // Use destination image type.
         $image->info['extension'] = $extension;
         if (!image_save($image, $destination)) {
             return FALSE;
         }
         $source = new stdClass();
         $source->uri = $destination;
         $source->uid = 1;
         // TODO: randomize? Use case specific.
         $source->filemime = $image->info['mime_type'];
         $source->filename = drupal_basename($image->source);
         $destination = $destination_dir . basename($destination);
         $file = file_move($source, $destination, FILE_CREATE_DIRECTORY);
     }
     $object_field['fid'] = $file->fid;
     $object_field['alt'] = devel_create_greeking(4);
     $object_field['title'] = devel_create_greeking(4);
     return $object_field;
 }
Beispiel #2
0
function fetch_page($page_url)
{
    $html = file_get_contents($page_url);
    // echo $html;
    if (!preg_match_all('/<img src2="([^"]+?)"/i', $html, $matches)) {
        throw new Exception("no img", 1);
    }
    foreach ($matches[1] as $image_url) {
        $file_name = substr($image_url, strrpos($image_url, '/') + 1);
        $file_name = __DIR__ . '/images/' . $file_name;
        if (is_file($file_name)) {
            echo "skip {$file_name}\n";
            continue;
        }
        echo "save {$file_name} \n";
        image_save($file_name, $image_url);
    }
    return count($matches[1]);
}
Beispiel #3
0
function fetch_page($page_url)
{
    $html = fetch_url($page_url);
    // echo $html;
    if (!preg_match_all('%<img src="([^"]+.douban.com/view/group_topic/large/public/p\\d+.jpg)"%i', $html, $matches)) {
        echo "no image in this page\n";
        return false;
    }
    foreach ($matches[1] as $image_url) {
        $file_name = substr($image_url, strrpos($image_url, '/') + 1);
        $file_name = __DIR__ . '/images/' . $file_name;
        if (is_file($file_name)) {
            echo "skip {$file_name}\n";
            continue;
        }
        echo "save {$file_name} \n";
        image_save($file_name, $image_url);
    }
    return count($matches[1]);
}
Beispiel #4
0
function save_scaled($img_name, $dst_image_name, $ext, $max_width, $max_height)
{
    $size = getimagesize($img_name);
    $width = $size[0];
    $height = $size[1];
    if ($max_width == 0) {
        $max_width = $width;
    }
    if ($max_height == 0) {
        $max_height = $height;
    }
    $src = image_create_from($img_name, $ext);
    if ($width <= $max_width) {
        if ($height <= $max_height) {
            $tn_width = $width;
            $tn_height = $height;
        } else {
            $tn_height = $max_height;
            $tn_width = round($max_height * $width / $height);
        }
    } elseif ($height <= $max_height) {
        $tn_width = $max_width;
        $tn_height = round($max_width * $height / $width);
    } else {
        $x_ratio = $max_width / $width;
        $y_ratio = $max_height / $height;
        if ($x_ratio <= $y_ratio) {
            $tn_width = $max_width;
            $tn_height = round($x_ratio * $height);
        } else {
            $tn_height = $max_height;
            $tn_width = round($y_ratio * $width);
        }
    }
    $dst = imagecreatetruecolor($tn_width, $tn_height);
    // imagecopyresampled($dst, $src, 0, 0, 0, 0, imagesx($dst), imagesy($dst), $width, $height);
    imagecopyresampled($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
    image_save($dst, $dst_image_name, $ext);
    imagedestroy($src);
    imagedestroy($dst);
}
Beispiel #5
0
function _agency_1_theme_settings_map($form, &$form_state)
{
    $validators = array('file_validate_is_image' => array());
    $file = file_save_upload('background_file', $validators);
    $map_file = file_save_upload('footer_contact_us_map_image', $validators);
    //Map image
    if (isset($map_file)) {
        // File upload was attempted.
        if ($map_file) {
            // Move the file, into the Drupal file system
            if ($map_filename = file_unmanaged_copy($map_file->uri, 'public://background_images', FILE_EXISTS_RENAME)) {
                //resize, if necessary
                $map_resized = image_load($map_file->uri);
                list($map_width, $map_height) = getimagesize($map_file->uri);
                if ($map_width > 150 || $map_height > 150) {
                    if ($map_width / $map_height >= 1) {
                        image_scale($map_resized, 150);
                    } else {
                        image_scale($map_resized, null, 150);
                    }
                    image_save($map_resized, $map_filename, FILE_EXISTS_RENAME);
                    $map_resized->status = FILE_STATUS_PERMANENT;
                    drupal_set_message('Uploaded image was greater than 150px.  Image has been resized.');
                }
                //end resize
                unset($form['footer_contact_us']['settings']['footer_contact_us_map_path']);
                $form['footer_contact_us']['settings']['footer_contact_us_map_path']['#value'] = $map_filename;
                $form['footer_contact_us_map_path']['#parents'] = array('footer_contact_us_map_path');
                form_set_value($form['footer_contact_us_map_path'], file_create_url($map_filename), $form_state);
                watchdog('Theme Settings', 'New Footer Map Image uploaded: ' . file_create_url($map_filename));
                drupal_set_message('Map Image uploaded.  URL: ' . file_create_url($map_filename));
            } else {
                form_set_error('file', t('Failed to write the uploaded file the site\'s file folder.'));
            }
        } else {
            // File upload failed.
            form_set_error('background_file', t('The image could not be uploaded.'));
        }
    }
}
/**
 * Save file uploaded by user and generate setting to save.
 *
 * @param <file> $file
 *    File uploaded from user
 *
 * @param <string> $banner_folder
 *    Folder where save image
 *
 * @param <string> $banner_thumb_folder
 *    Folder where save image thumbnail
 *
 * @return <array>
 *    Array with file data.
 *    FALSE on error.
 */
function _black_lagoon_save_image($file, $banner_folder = 'public://blacklagoon-banner/', $banner_thumb_folder = 'public://blacklagoon-banner/thumb/')
{
    // Check directory and create it (if not exist)
    _black_lagoon_check_dir($banner_folder);
    _black_lagoon_check_dir($banner_thumb_folder);
    $parts = pathinfo($file->filename);
    $destination = $banner_folder . $parts['basename'];
    $setting = array();
    $file->status = FILE_STATUS_PERMANENT;
    // Copy temporary image into banner folder
    if ($img = file_copy($file, $destination, FILE_EXISTS_REPLACE)) {
        // Generate image thumb
        $image = image_load($destination);
        $small_img = image_scale($image, 300, 100);
        $image->source = $banner_thumb_folder . $parts['basename'];
        image_save($image);
        // Set image info
        $setting['image_path'] = $destination;
        $setting['image_thumb'] = $image->source;
        $setting['image_url'] = '<front>';
        $setting['image_title'] = '';
        $setting['image_weight'] = '';
        $setting['image_visibility'] = '*';
        return $setting;
    }
    return FALSE;
}
Beispiel #7
0
    </div>
    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="../../assets/js/bootstrap.js"></script>
  </body>
    <script>
    $('.carousel').carousel({
        interval: 3000 //changes the speed
    })
    </script>
</html>
    <?php 
if ($_POST) {
    require '../db/db_connect.php';
    $conn = connection();
    $title = isset($_POST['title']) ? $_POST['title'] : "";
    $date = isset($_POST['date']) ? $_POST['date'] : 2010;
    $des = isset($_POST['des']) ? $_POST['des'] : "";
    $image = "";
    if (isset($_FILES['files'])) {
        $files = $_FILES['files'];
        $dir = '../../gallery/img/';
        $image = image_save($dir, $files);
        $query = "INSERT INTO Gallery(Title,Img_name,Des,Add_date) VALUES('{$title}','{$image}','{$des}','{$date}')";
        if (!$conn->query($query)) {
            echo $conn->error;
        }
    }
    //
}
Beispiel #8
0
function http_image_download($img, $id, $folder)
{
    $file = remote_image_new($img);
    if (!$file || gettype($file) == "array") {
        return false;
    } else {
        $file_ext = strtolower(substr($img, strrpos($img, '.') + 1));
        $real_url = 'media/' . $folder . '/' . $id . '.' . $file_ext;
        image_save($settings->upload_path . $real_url, $file);
        return "/" . $real_url;
    }
}