
Image Extractor is a WordPress plugin that extract the first image from the post and display it. The "Image Extractor" main feature is the capability to resize the image found to a wanted size. The final image is cached in a folder, so you can obtain better performances.
How to install
- Download the .zip file and extract it
- Upload the extrated folder (imageExtractor/) to the WordPress plugins folder (wp-content/plugins/)
- Configure the imageExtractor.php file and set the right cache folder. Make sure it’s writable.
- Activate the plugin from the WordPress back office panel
How to use
Image Extractor will enable a new template function. It output a complete IMG tag to be inserted into your HTML code. The image source is retrieved from the first image found in the current post. Here is an example showing you how to use it:
<?php
while (have_posts()) : the_post();
image_extractor(true, 1, 395, 0, '', '', '<div>', '</div>');
the_excerpt();
endwhile;
?>
The syntax is:
image_extractor($resize=false, $resize_type=1, $width='', $height='', $class='', $id='', $prefix='', $suffix='')
where:
- resize: indicate if the plugin has to resize the image and store it in the cache folder
- resize_type: there are 3 type of resizing:
- 0 -> image will be resized to the new output size, regardless of the original aspectratio. (default)
- 1 -> image will be cropped if necessary to preserve the aspectratio and avoid image distortions.
- 2 -> image will be resized preserving its original aspectratio. differences to the new outputsize will be filled with white
- width: the destination width. If resize is false, this property only add/change the WIDTH attribute of the IMG tag
- height: the destination height. If resize is false, this property only add/change the HEIGHT attribute of the IMG tag
- class: add or change the CLASS attribute of the IMG tag
- id: add or change the ID attribute of the IMG tag
- prefix: add a prefix to the resulting IMG tag
- suffix: append a suffix to the resulting IMG tag
The resulting effect is cool! You can resize the post dimension as you want! Here is a screenshot!
PS: Wowww, WordPress staff has just approved my first plugin!!! I’m very very happy. You can find "Image Extractor" on the official WordPress plugin repository.
154 commenti
Ciao Mick, e complimenti per il plugin. Ho qualche problema nell’installazione: se wordpress è installato nella root, e la cartella cache (777) è /images/thumb qual è il percorso corretto nel file php? /images/thumb/ , giusto?
Ricevo questo errore:
Warning: Cannot modify header information – headers already sent by (output started at /home/../public_html/wp-content/themes/tema1/header.php:4) in /home/../public_html/wp-content/plugins/imageExtractor/class.ImageToolbox.php on line 692
Ciao Franco,
sinceramente non saprei darti un aiuto. Dovresti dirmi cosa c’è alla riga 4 di header.php e la riga di codice dove invochi imageExtractor.
Ciao,
mick
giusto, hai ragione. Alla riga 4 c’è il title, che ho commentato con , questa sera provo a toglierla, strana cosa. Scusa la poca dimestichezza, ma la linea 692 non c’è, puoi indicarmi cosa dovrei controllare? Grazie per il supporot
Hello
This is a fantastic plugin, I am using it here:
http://www.holster.co.uk/wordpress/archives/24
The only problem is that I am still getting the image shown as part of the original post. How can I only show the text of the post, or is there an equivalent ‘text-extractor’ plugin?
Basically I would like to be able to show the text and the image of a post independently, and your plugin has helped me get half way there….
Una domanda: ma c’è un check circa la presenza o meno di un’immagine nel post? Perché ho un errore che parrebbe far presumere di no. :p
Hai ragione. Non ho controllato, ma credo che il controllo manchi. Verifico ti faccio sapere di meglio! Ciao!
You have a bug if you have a post with no images… it still tries to resize.
I added this at line 100 of image extractor.php and it seems to have fixed it:
if ($attribArr==false) return;
I was also getting this error:
Warning: Cannot modify header information – headers already sent by (output
For line 692 of class.ImageToolbox.php so I simply commented it out and everything seems to work fine.
Hi, when the post don’t have an image, the function image_extractor(…) outputs an img tag like this: and will display an empty image on browser. You need to check if you have an image on the post… Best regards, Cip.
Ottimo plugin!! ma purtroppo mi da un errore durante la validazione.. “”
a causa dell’ 1 dopo
Thanks Luke, I’ve updated the Image Extractor project with your tips and I hope many problems could be resolved.
For those who catch some problems, I suggest to download the new version.
mitico plugin, purtroppo mi produce un errore di validazione xhtml per ogni immagine inserita
Has anyone modified the plugin to allow for the inclusion of the extracted image an RSS feed?
I am not good at php, but I founded and fixed 2 erros I was getting:
1- The generated code was showing a number one just before src, like this: <img 1 src=”file.png” width=”50″ alt=”" />
I added a str_replace to take that one out.
2- The resize method 1 was generating weird images with lots of black spaces (even with the background color was white) and with just a few pixels of the original image. I really do not know the reason for this, but I solved changing the save extension from png24 to jpg.
It is all working good now, but maybe you can find out the reason why it was acting like that. If it helps, my websites are hosted at BlueHost and the line code was identical to yours in How to Use session. Those were the only code changes I made.
Hi Rafael or Mick!
I have the same problem with the cropping method 1. That’s the one I would like to use. But I get these ugly black borders, and the actual image is hardly visible (too narrow). Please send me your updated plugin, I really would like to use it here: http://bentographics.com/site/
It would be great to have an option, where the plugin should crop, i.e. center of the image, otherwise one ends up with a lot of borders and not much of the actual image or graphic you want to display as thumbnail.
Please write me, my email is on my website or use bentoenterprises {at} gmail {dot} com. Thank you lots! b
Ciao, complimenti per il plug-in !! volevo segnalarti che ho inserito questo codice nell’index.php , dopo aver installato il plug-in, purtroppo però non accade nulla, le GD funzionano correttamente, puoi darmi qualche consiglio ?
Grazie mille
Mi spiego meglio, inserendo il tag nel loop del file home.php ( che è poi la pagina iniziale del sito ) compare solo l’header, tutto il resto della pagina è bianca, quindi suppongo che il loop venga bloccato dal tag image_extractor..
I’ve modified you plug in get a parameter that tell him to “echo” or “return” the results.
this is useful if you wanna use the URL returned in some other php function or variable.
maybe in the next version u can incorporate that.
Like Robert McPeak asked, I also have a need for this sort of plugin. One reads WordPress feeds, pulls the first image out of said feed and displays the image, post title and a link from the post title to the actual post. I probably could mash one up, but if someone already invented this wheel, I’d be interested. Thanks!
Problems installing. I am setting the php file to the correct writable folder and am attempting to install. Getting all sorts of errors once i click the “activate” button. Then i have to deactivate immediately or i have an issue with my header in the wp-admin? Anyone else run into this issue?
BTW – same error as Franco. Can’t read your response…
Your plugin sounds great, is it possible to specify one or several categories in the function? Thx!
And sorry, I forgot to ask: does it work with WP 2.2.2?
[...] sono nuova. Ho recentemente installato la versione 2.2 di wordpress. Ho qualche problema con questo plugin Ho provato ad inserire il codice nel template di default, nel file index.php, ma mi è risultato [...]
could you tell me how to establish a permalink to PNG image?
I tried the following syntax, but I couldn’t it.
“>’,”);
?>
Thanks for this plugin.
could you tell me how to establish a permalink to PNG image?
I tried the following syntax, but I couldn’t it.
<?php
$posts = get_posts('numberposts=1&category=6');
foreach($posts as $post) :
setup_postdata($post);
image_extractor(true, 1, 200, 0,'img_L','','<a href="<?php the_permalink() ?>">','</a>');
?>
Thanks for this plugin.
works with wordpress 2.3
Hei! Thanks for your great plugin but i have a problem. It doesn´t resize the image but the GD Support er enabled and the folder has 777. Do you have any idea?
Greatings!
Meerblickzimmer
Hello Mick.
I’am trying to find plugin or function, to extract an image from post, resize it, & put above the title of post in “Recent Posts” field (in the slidebar).
Is it possible to do with your script?
X Meerblickzimmer: perhaps the image is too big, and the php exceed the allowed memory.
X Stanly: My plugin works exactly as you describled. Try it!!!
@Mick: post_max_size = 8M or what must i check? Thanks for help! M
x Mick
I tryed to install Image Extractor, but I failed… =( few strange errors appeared & I just deactivate it. Today I surf your blog & understand all usefulness and power of your plug-in. As soon as I’ll write a tutorial for you about creating headers like mine, I’ll try to install plug-in one more time… because I really need its functionality for dezignus.com, & for my future projects!
(ps. Sorry for my English, I’am Russian)
When I try to resize, i keep getting the following error in my log:
PHP Fatal error: Image: Outputwidth and -height must be integers greater zero
How can i save the resized image in jpg ? The thumb are too big
and is there a way to choose where crop ?
Ciao Mick,
C’è un modo per fare si che l’immagine sia un link al post?
Io ho provato così:
', ''); ?>Ma la funzione “the_permalink” non funziona (scusa il gioco di parole).
Hai qualche suggerimento?
Ciao e grazie.
Giovanni
hi mick,
I’m currently using wp 2.3.2, when i enable this plugin in my sidebar this error comes out.
[quote]require_once(dddd.com/wp-content/themes/default/sidebar.php) [function.require-once]: failed to open stream: No such file or directory at dddd.com/wp-includes/theme.php (440)
timed at 14-Jan-2008 13:26:28
[/quote]
any idea guys
Scusate ma a me da errore se lo metto nel mio tema. come mai?
ah si io uso wp 2.3.2
Great Plugin! How can you make it display a default image if it does not find an image? Thanks!
Great Plugin. How do you set a default image if it doesn’t extract one?
Matt
Hi there,
GREAT plugin! I use it on my own site no problems, but I’m doing a new site for someone else now and I’m getting the same error as abelafonte when I set resize to true:
Fatal error: Image: Outputwidth and -height must be integers greater zero.
…but I have them both set to 100
Also, where do I create the image cache folder? Where is the location /mat/thumb/ relative to?
®
Is it possible to use this plugin to show the image from the previous or next posts? I want to do a previous and next post preview thumbnail on single view pages…
®
I’m using Resize Type 1 and it’s not working correctly, as described by others. It crops the images incorrectly, leaving big black spaces.
Is ImageExtractor compatible with WordPress 2.5? Thanks!
I’m using it on my site with WordPress 2.5 no problem…
®
ciao, il tuo plugin sarebbe per me una mano santa…se solo riuscissi a farlo funzionare!
questa è la funzione che scrivo:
image_extractor(true, 1, 240, 180, ‘post-image’,”, ”, ”);
ho WP 2.3.2, la cartella per le immagini è abilitata alla scrittura, ho il supporto GD sul server.
Ma con il true non mi funziona, non mi resiza le immagini e non succede nulla. Se metto false invece funziona, ma non è quello che mi serve, perchè mi stretcha le img.
Questo è ciò che scrivo nel file di configurazone della dir:
$destinationDir=”/_img/thumbs/”;
Quale potrebbe essere il problema?
Grazie in anticipo per il supporto, ciao
I want to activate this plugin on localhost (wampserver), but I can not, because it gives error. How to install it?
Will the “Image Extractor” plug-in be updated to address the issues with incorrect cropping (using resize type 1) and image quality? Sometimes I notice the new images are of great quality.
Looking forward to the future release!
This is a great plugin. Is there anyway to make it work with the new WP2.5 gallery if there is a gallery instead of an image.
good work, very much appreciated!