Image widget
hefox - August 15, 2009 - 23:39
| Project: | Textimage |
| Version: | 6.x-2.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | minor |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
I think having a textimage /image/ widget would be a great extrension for textimage.. . Or better yet, a token-able default text=>image for an image not provided. Combining it with image cache & image cache actions... It's sexy. Really sexy. Realllly sexy. Get all the extra functionality that image cache/actions has.. :)
ATM I don't have time to do this personally, but here's an example I just (hopefully) got working of taking a text and saving it into a file field
field_teaser is a textfield and field_image is a file field with image widget.
<?php
if (!$node->field_image[0]['fid'] && $node->field_teaser[0]['value']) {
//$node->field_teaser[0]['value']
$img=textimage_image_from_preset(1, $node->field_teaser[0]['value'], array());
$path = file_directory_path(). '/'.time() . rand(1000, 9999) .'.png';
imagepng($img,$path);
imagedestroy($img);
$file = field_file_save_file($path,array(), file_directory_path());
$node->field_image[0] = (array)$file;
}
?>
#1
I'm not sure exactly what you're trying to achieve, it appears from your code that if there is an uploaded file and a textfield, use the content of the textfield to overwrite the contents of the uploaded file.... then why bother uploading the file in the first place?
You can use a Textimage preset as a CCK formatter for a textfield already, so I would think it would be better to go down that track.
It is also possible to use a generated Textimage with ImageCache, but admittedly not very straight forward, I guess I could look into possibilities to increase interoperability.
Cheers,
Deciphered.
#2
(Mostly just posted that in case other's desire the functionality and want a quick fix; wouldn't use that code. Also, it only replaces the image if none is supplied. Basically, acting as a default image creation if none is supplied).
I'm using that code atm, so right now don't have any pressing need for it, but I think some interaction with imagefield/imageCache expand the uses of text image greatily.
For example, I'm using the above combined on a personal photo/some text site, where the navigation between the items in the main taxonomy view is done via one image. I needed to combine it with image cache for the varying sizes presents and rounded corners (to keep things unified.. or rather rounded corners is damn pretty). http://foxis.intheclosets.com/whatismine/lizzie?page=7 Here's an example of it, both the image to the left and the thumbnail to the right are the same image generated via text image, stored in image field then re manipulated with image cache.
Advantages:
One image field is simpler to deal with then one image and one text field overall when one basically is desiring one image per content type, like thumbnails etc.
Expended manipulation via imageCache and image cache options. Initial reason behind exploring this was unable to find a max height for text image like imageCache has XD (and then.. rounded corners!)
Thinking about it more, instead of an image widget, probably most useful would be an "default image to create is supplied" that takes in node tokens => text. Though an issue about that would be image field default image isn't set as the image but instead uses the image if none is supplied, whereas what I described above would most likely create the image onsave.
Flow:
Imagefield default textfield content type/widget settings:
Text field/area that takes in node tokens.
For example: [field_teaser-raw]
Node is submitted, if field_image is empty, create an image replace. That'd allow for users to submit their own images, then fallback to a created one if none supplied
My guessing is this add-on would be best as a different module, and I really should just try and do it myself... after figuring out a more elegant way of doing the above; tried using the function I took the code from but it kept 404ing on me despite various things including http_requesting and being able to see the actual image; i assume due to it's cached nature?