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;
 }
示例#2
0
文件: template.php 项目: ehazell/AWPF
/**
 * IE Header and Background
 */
function az_gov_preprocess_html(&$vars)
{
    $meta_ie_render_engine = array('#type' => 'html_tag', '#tag' => 'meta', '#attributes' => array('content' => 'IE=edge,chrome=1', 'http-equiv' => 'X-UA-Compatible'), '#weight' => '-99999');
    drupal_add_html_head($meta_ie_render_engine, 'meta_ie_render_engine');
    //if a background image is uploaded, it will apply the css needed
    if ($image = theme_get_setting('main_background')) {
        $background = image_load(file_load($image)->uri);
        $bg_url = file_create_url($background->source);
        $bg_width = $background->info['width'];
        $bg_stretch = '
    @media(min-width: 768px) {
        body {
          background: url("' . $bg_url . '") no-repeat center center fixed !important;
          -webkit-background-size: cover !important;
          -moz-background-size: cover !important;
          -o-background-size: cover !important;
          background-size: cover !important;
        }
      }';
        $bg_repeat = '
    @media(min-width: 768px) {
        body {
          background: url("' . $bg_url . '") fixed !important;
          background-size: contain;
        }
      }';
        //if the image is under 300px wide, it will  be repeated, if not, it will stretch
        if ($bg_width > 300) {
            drupal_add_css($bg_stretch, 'inline');
        } else {
            drupal_add_css($bg_repeat, 'inline');
        }
    }
}
示例#3
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.'));
        }
    }
}
示例#4
0
    unset($_POST['units']);
    unset($_POST['mb_flag']);
    unset($_POST['NewStockID']);
    unset($_POST['dimension_id']);
    unset($_POST['dimension2_id']);
    unset($_POST['selling']);
    unset($_POST['depending']);
    unset($_POST['barcode']);
    unset($_POST['weight']);
    $_POST['New'] = "1";
}
if (isset($_POST['deleteImage']) == '1') {
    $sql = "update stock_master set image='' " . "where stock_id='{$stock_id}'";
    $result = db_query($sql, "could not delete image");
}
$blob = image_load($max_image_size);
if (isset($_POST['addupdate'])) {
    $input_error = 0;
    if ($upload_file == 'No') {
        $input_error = 1;
    }
    if (strlen($_POST['description']) == 0) {
        $input_error = 1;
        display_error(tr('The item name must be entered.'));
        set_focus('description');
    } elseif (strlen($_POST['NewStockID']) == 0) {
        $input_error = 1;
        display_error(tr('The item code cannot be empty'));
        set_focus('NewStockID');
    } elseif (strstr($_POST['NewStockID'], " ") || strstr($_POST['NewStockID'], "'") || strstr($_POST['NewStockID'], "+") || strstr($_POST['NewStockID'], "\"") || strstr($_POST['NewStockID'], "&")) {
        $input_error = 1;
/**
 * 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;
}
<?php

// @todo mover a un preprocess
$created = format_date($node->created, 'custom', 'd-F-Y');
$has_image = isset($content['field_main_image']);
$has_image_class = $has_image ? "with-image" : "no-image";
if ($has_image) {
    $uri = $content['field_main_image']['#items'][0]['uri'];
    $img_path = file_create_url($uri);
    $img = image_load($uri);
    hide($content['field_main_image']);
}
?>

<?php 
if ($has_image) {
    ?>
  <style media="all" type="text/css">
    #id-node-<?php 
    echo $node->nid;
    ?>
 {
      background-image: url("<?php 
    echo $img_path;
    ?>
");
    }
  </style>
<?php 
}
?>
示例#7
0
/**
 * Implement HOOK_views_post_render().
 */
function bc_theme_views_post_render(&$view, &$output, &$cache)
{
    if ($view->name == 'presentation') {
        // Get one presentation image to be fallback if js in not active.
        $fb_image = $view->result[0]->field_field_presentation_image_2;
        $fb_file = image_load($fb_image[0]['raw']['uri']);
        $alt = t('Delícias que derretem na boca!');
        $fb_image = array('#theme' => 'image', '#alt' => $alt, '#path' => $fb_file->source, '#width' => $fb_file->info['width'], '#height' => $fb_file->info['height']);
        $output .= theme('presentation_fallback', array('fallback' => $fb_image, 'alt' => $alt));
    }
}
<div class="product-list">
<div class="row">
<?php 
//var_dump($element);
?>
  
    <?php 
if ($element) {
    ?>
        <?php 
    foreach ($element as $photo) {
        ?>
            <?php 
        // var_dump($photo);die;
        $file = file_load($photo->fid);
        $image = image_load($file->uri);
        $image_content = array('file' => array('#theme' => 'image_style', '#style_name' => 'large', '#path' => $image->source, '#width' => $image->info['width'], '#height' => $image->info['height']));
        // $city_obj = taxonomy_term_load($photo->city);
        $location_obj = taxonomy_term_load($photo->location);
        $pg_obj = node_load($photo->pgrapher);
        ?>
            
                <div class="col-sm-6 col-md-4">

                    <div class="thumbnail">
                        <figure>
                            <?php 
        print '<a href="' . $base_path . 'node/' . $photo->nid . '">' . drupal_render($image_content) . '</a>';
        ?>
                        </figure>
                        <div class="caption">
    ?>
</a></h2>

    <?php 
    $cont = 0;
    ?>
    <?php 
    foreach ($blocks as $block) {
        ?>
        <?php 
        // get vars
        $tid = $block['field_bloque_home_tid']['und'][0]['tid'];
        $txt = $block['field_bloque_home_txt']['und'][0]['safe_value'];
        $img_src = file_load($block['field_bloque_home_img']['und'][0]['fid']);
        if ($img_src) {
            $img = image_load($img_src->uri);
            $img_render = array('file' => array('#theme' => 'image_style', '#style_name' => 'large', '#path' => $img->source, '#width' => $img->info['width'], '#height' => $img->info['height']));
        }
        $class = '';
        switch ($contents_num) {
            case 1:
                $class = 'col-md-8 col-sm-8';
                break;
            case 2:
                $class = 'col-md-8 col-sm-8';
                break;
            case 3:
                $class = 'col-md-4 col-sm-4';
                break;
        }
        ?>