Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // hook_menu()
- function cdnimage_menu() {
- $items['cdnimage/%'] = array(
- 'title' => 'Upload CDN Image',
- 'page callback' => 'cdnimages_upload',
- 'page arguments' => array(1),
- 'access callback' => TRUE,
- 'type' => MENU_NORMAL_ITEM,
- );
- return $items;
- }
- //
- function cdnimages_upload($product_id) {
- if (is_numeric($product_id)) {
- $toggle = db_query('SELECT field_product_type_value
- FROM field_data_field_product_type
- WHERE entity_id=:entity_id', array(':entity_id' => $product_id))->fetchField();
- $result = db_query('SELECT it.delta, fm.uri, lms.field_lms_id_value AS lms_id
- FROM file_managed fm
- INNER JOIN field_data_field_product_images pi ON pi.field_product_images_fid = fm.fid
- INNER JOIN field_data_field_product_images_with_tags it ON it.field_product_images_with_tags_value = pi.entity_id
- INNER JOIN field_data_field_lms_id lms ON lms.entity_id = it.entity_id
- WHERE it.entity_id = :entity_id', array(':entity_id' => $product_id));
- $rows = $result->fetchAll();
- $image_styles = array(
- '240' => '240w_240h',
- '50' => '50w_50h',
- '110' => '110w_110h',
- '320' => '320w_320h',
- '480' => '480w_480h',
- '800' => '800w_800h',
- );
- $display_style = array();
- foreach($image_styles as $key => $value) {
- $display_style[$key] = image_style_load($value);
- }
- foreach($rows as $row) {
- $string_lower = explode(".", strtolower($row->uri));
- $ext = end($string_lower);
- print $row->uri;
- foreach($image_styles as $key => $value) {
- $destination = "rcf:///".$row->lms_id."_".$row->delta."-".$key.".".$ext;
- print "$destination --- $value <br>";
- image_style_create_derivative($display_style[$key], $row->uri, $destination);
- }
- print "<br><br>";
- }
- return;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment