Hi,
I need to calculate the dimensions of an image that is created through views + cck (computed field + imagefield). I'm pretty fresh to php and am having trouble figuring out how to implement the code in computed field. I took a stab at it:
$image = open_image($node->field_image[0]['filepath']);
$node_field[0]['value'] = imagesx($image);
I have another field in my content type for the image and I'm trying to figure out the best way to grab it and display the dimensions in my view. Here's an export of my content type:
$content[type] = array (
'name' => 'Press Item',
'type' => 'press',
'description' => 'This is a single press item.',
'title_label' => 'Title',
'body_label' => '',
'min_word_count' => '0',
'help' => '',
'node_options' =>
array (
'status' => true,
'promote' => false,
'sticky' => false,
'revision' => false,
),
'comment' => '0',
'old_type' => 'press',
'orig_type' => '',
'module' => 'node',
'custom' => '1',
'modified' => '1',
'locked' => '0',
'ant' => 0,
'ant_pattern' => '',
'ant_php' => 0,
);
$content[fields] = array (
0 =>
array (
'widget_type' => 'computed',
'label' => 'Image_Width',
'weight' => '0',
'description' => '',
'required' => '0',
'multiple' => '0',
'code' => '$image = open_image($node->field_image[0][\'filepath\']);
$node_field[0][\'value\'] = imagesx($image);',
'display' => '$image = open_image($node->field_image[0][\'filepath\']);
$node_field[0][\'value\'] = imagesx($image);',
'display_format' => '$display = $node_field_item[\'value\'];',
'store' => 1,
'data_type' => 'int',
'data_length' => '4',
'data_default' => '',
'data_not_null' => 0,
'data_sortable' => 1,
'field_name' => 'field_image_width',
'field_type' => 'computed',
'module' => 'computed_field',
),
1 =>
array (
'widget_type' => 'image',
'label' => 'Image',
'weight' => '2',
'max_resolution' => '640',
'image_path' => '',
'custom_alt' => 0,
'custom_title' => 0,
'description' => '',
'field_image_upload' => '',
'upload' => 'Upload',
'default_value_php' => '',
'required' => '1',
'multiple' => '0',
'field_name' => 'field_image',
'field_type' => 'image',
'module' => 'imagefield',
),
);
Does this look close? Or is there an easier way? Thanks!