By hayskelly on
I have a multi user blog, what I want to do is make a view that shows the first image from body. The thought process I have so far is, find the first img tag in the body, extract the src, wrap the src in an img tag, show that on the /blog page so when people visit it they see a nice photo from the body.
Is that possible? ok, I know its possible, its Drupal. Does anyone know how to do this, or where I can go to find out some info on this.
Thanks
Comments
Not to sure how you could do
Not to sure how you could do about doing this. I normally create a image field before the body tag and assign that image as the blog image on the list page, but that might not suit your sites needs.
This is not possible. Use a
This is not possible. Use a separate image field if you want to use the picture elsewhere.
What do you mean this isn't
What do you mean this isn't possible? This is Drupal, everything is possible.
I was looking on a few php sites, and I think all you have to do is search the body array for the first img tag, extract the text inbetween the quotes on the src part of the image tag (src="the url of photo").
From there it is a simple image cache theme to make it the size I am looking for. I just don't know how to do the first part. Any ideas?
That's the right mindset :) I
That's the right mindset :)
I guess lots of things are possible if you know your way around php (which I don't). Just saying you can't do this with Views out of the box.
Not sure if this is what you
Not sure if this is what you mean but I was sure I had done this in an experiment with the timthumb script and then later as another test using methods wordpress dev's used to find and extract the first
from the body. This I did in the node tpl. I'll see if I can get it, I remember searching for this "get first image in node body" and found this http://bit.ly/AIave on which I based it. I think :)
Hello, The link you showed is
Hello,
The link you showed is exactly what's needed, but I don't know how to adapt it to Drupal.
I have exactly the same problem as OP.
Ideally, the PHP code snippet should be in a computed field. The thing is, I don't know either how to call the node's body variable (is it $node->body[0]['value'] ?), or how to use Imagecache to display this image.
Any help would be greatly appreciated.
Regards,
Ralt
Here's what I've done up
Here's what I've done up until now.
I've created a computed field.
Computed code :
Display format :
This works great. It does take the first picture of the node, and prints it.
But I can't get it to work with Imagecache. In my view, I can choose the field, but it's treating the field just as any other text field, and it's not leaving me any option to choose an image format.
Ok, found it! The thing is,
Ok, found it!
The thing is, Imagecache does not accept external urls.
I had to install Imagecache external (v1, because v2 is still in dev). After configuring this properly, I changed a little bit my computed field according to Imagecache external instructions.
New Display format :
And it works like a charm!
Nice one Ralt! This is going
Nice one Ralt! This is going to be very useful.
Update. Actually, the not-dev
Update. Actually, the not-dev version of ImageCache External is kind of buggy. Returning 404 errors when there is special characters in the URL.
I used Imagecache External 6.x-2.0-beta2, and it works great. Looking at the code, I don't know why it's just in dev version, but anyway this just works.
Though, there is a little change to do in the computed fields.
Computed code :
Change 'preset-name' to match your own imagecache preset.
Display format :
Change the values of width="" and height="" to match the ones of your imagecache preset.
I'm glad it helped you bukem :)
Hi Ralt, Is it possible to
Hi Ralt,
Is it possible to take the image that you extracted from the body and put it in into an image field?
This would be the most flexible solution I guess.
I insert images in cck text field with wysiwyg editors, but then these images can't be used with imagecache and views, because they are considered text.
With the cck computed field, and your code, I am able to display the extracted image in the computed field, under the text field. What I would like to do is put that image in a cck image field.
Hi Taesto, I guess that to do
Hi Taesto,
I guess that to do this, you should do everything in the computed code's part, something like this :
Change 'your_image_field[0]' with your image's field. I'm not sure about the '[0]' part, though, need testing.
Then, don't put anything in the display format, since your computed field should not display anything.
Tell me if that works!
The code you wrote
The code you wrote in
http://drupal.org/node/1045712#comment-4300894
works well, I see the image displayed in the computed field.
But, what you wrote in
http://drupal.org/node/1045712#comment-4311020
does not work for me. I only see the alt text. Too bad, because after some thought I think this would actually be better than adding an image field. Maybe Imagecache external has a problem because I am in "private download" mode? The problem is that I must have private IMCE folders for each user, and I think for this I must have private download.
I also have filesize() errors when I try to use the solution
https://drupal.org/node/991586
This is really confusing. Maybe I should try version 1 of Imagecache external, to see if it works any better.
I can see the image file is fetched by the computed field, but then I can't do anything with it at the moment...
Hi, Our problems are very
Hi,
Our problems are very different. Indeed, I used Views with Imagecache preset to display the collected images. You can choose to display a computed field as raw text, which I did and works great.
I think your field is well populated, but can not be displayed as full HTML, so only the ALT text appears. You should check out on this side.
With Firebug, can you see what HTML is outputted in your ALT part?
Following the instructions in
Following the instructions in http://drupal.org/node/1045712#comment-4311020 , it seems to work. Selecting raw-text option in Views, I can now see the thumbnails displayed in my Views. This is a huge step forward! By the way, I have no idea why it works now and why it didnt work before... Just glad the pics are showing. However, the thumbnails are distorted :S
Do you have the same issue?
I put the preset 'crop' and width = 150 , height = 150. This preset is supposed to do a scale & crop, but it looks like something got lost on the way.
It is usable as is, but if I could get the preset to work like it should, it would be PERFECT.
Have you set width and height
Have you set width and height correctly in the Display format ?
BTW, Crop and Scale&Crop are two different presets in ImageCache.
A much much better solution
Hi Ralt,
Just thought I'd let you know of the solution I finally found.
I was trying to take the inline image and save it in an image field. But I just found out about the Insert module. It seems a much easier and future proof solution than using IMCE to upload the file into the textfield, and then a computed field to put it into the imagefield, to be used with imagecache. Just installed Insert module and it is PERFECT! And works with Views also! And I'm switching back the filesystem to public (had to put it in private because with IMCE, users could see each others' folders by default). So a much leaner website also.
So after spending almost a week trying to make things work with a custom module or a computed field, I stumbled upon mustarseed's podcast on Filefield Insert, totally by chance (I was looking for a way to get the fid of IMCE uploaded images). Whew!
Hi, Glad you found a
Hi,
Glad you found a solution!
You also had me discovering this module, so thank for your feedback!
Drupal 7
I look solution for Drupal 7
this code don't work for me in computed fields.
can you help me ?
Thanks, Ralt. Quite useful.
Thanks, Ralt. Quite useful.
i like you comment. "What do
i like you comment. "What do you mean this isn't possible? This is Drupal, everything is possible." yes. never tell drupal cannot do this and that. you can say no programmer is thinkin about doing it yet.
belajar drupal, makan drupal, tidur drupal
http://drupal.org/project/ins
http://drupal.org/project/insert
So glad that I came across
So glad that I came across this post, I have exactly the same issue and have been looking for a solution. Being new to Drupal and web dev as a whole, I did not know if this was possible, it obviously is. My issue now is how I would go about implementing this. I have a front page view that displays tumblr posts, some images are too big or dont display properly due too image size. Sometimes it comes off as stylish and other times it leaves much to be desired. In newbie terms how would I get this done.
www.hoodhippeez.com
In D7 Views 3.x...
In D7, if you don't need to apply image styles or anything like that you can simply inset the body field and select to only allow
tags in the rewrite results section. It's quite simple actually, I'm not sure why everyone is complicated the process.
tried but this still allows many other tags
Just want image tag!
I dont understand what you
I dont understand what you want exactly.
Which image do you want to display?
If you explain i ll try to find the solution.
Thanks
- - -
Mani
I agree that that would be a
filtering out all tags except img tags would be a nice elagant solution... if it worked. But for me, there's multiple images and theres text outside of p tags that gets mixed in with the images. Just need one image!
Trying to pull all Image Tags from Body Content
Hi All,
I am working on making a website ADA Compliant and through doing that we are creating views in the dashboard to pull all images to easily update alt and title tags.
My issue is the body content, Is there an easy way, using views, to pull <img/> tags into a view and see if they have alt tags?
Any help would be appreciated!
Thanks!