
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, compliementi per il plugin. Io ho un problema, non riesco a capire perchè quando lo inserisco mi rovina tutta la disposizione del sito.
Posso collegare il plugin al codice che elenca i post recenti o quelli più letti?
Grazie Mille
Andrea
I found a fix for the black areas that many of us were getting when imageExtractor improerly cropped an image. Open up ‘imageExtractor.php’. go to line 112. it should look like this:
[code]
$thumbnail->setResizeMethod('workaround');
[/code]
change it to this:
[code]
$thumbnail->setResizeMethod('resize');
[/code]
Thats it.. fixed it for me!
Thakns for this great plugin!
Ciao, bellissimo plugin ma anche a me non funziona in modalità $resize=true
Credo che come gli altri amici qui sopra non sia ben chiaro se la path della cache nella configurazione debba essere assoluta a partire dalla root o relativa al template…
Potresti dirci la path corretta da configurare.
per il resto è quello che cercavo e per farti felice ti dirò di più: il tuo plugin è risolutivo per il template “Revolution”…
Grazie ancora…
Guido
First: Excellent plugin, thanks a lot.
One one site (WP 2.5.0) it works nicely – but in another site (http://jonassmith.dk/weblog/, WP 2.5.1) thumbs don’t get generated. Inserting the first image without resize works fine, though.
Anyone know what might be the problem? Can it be related to the lates WP version?
(Thumb folder is fully writable).
Thanks!
- Jonas
Hi this is an awsome plugin and i have managed to get it working on my site fine for images that are put up manually into each post. But i was wandering if anyone knew if there was a way of manipulating this plugin so that i can extract images from posts that use a “random Image” plugin, or if there is another plugin out there that does this. If so it would be a great help.
Cheers
Bobby
i got image extractor to work without having a local location on my server, or using uploaded images. all my images are remotely hosted on photo bucket or imagshack, so basically have a “featured” sidebar with loads of images, clickable to the post itself (usually could only done by using uploaded images and plugins).
my question is, if you can incorporate this with the “relatest posts with thumbnails” plugin, it would be the best plugin ever. having related articles with thumbnails, WIHOUT having the thumbnails’s source coming from physical uploaded images. but from remote hosted images instead… if i can use “related posts to thumbnails” to call “extract_images()” as the output, it would be great, please show me how.
funny. i´ve got the same problem as Jonas Smith.
Inserting the first image without resize works fine, the second image – if i have the resize option (TRUE) turned on – wont be shown. It will be empty.
WP 2.6. Any ideas?
thx
This is what i have been looking for
yea, i figured it out.
@ Jonas Smith: maybe a solution for you too!
If the pictures are not saved in the original wp-content/upload/ [...] folder, image-extractor
doesn´t work. so, if your image-link in the post is something like “http://www.example.com/image.jpg”, image-extractor although work with “false”, but the crop function is disabled.
So, make sure, that your images always are linked to your upload folder!
hello
I’m having some trouble setting the cache folder
$destinationDir=”wpcontent/uploads/”;
what should i have here?
thanks
Hi,
I would love to use this plugin but when I try to activate it (wordpress 2.5) it generates an error:
html = “”; $this->html=$htmlcode; return true; } function LoadHTML($filename) ……………..
any ideas what may be wrong? I have looked everywhere for a solution but havent found an answer… your help would be much appreciated
Thanks
I
Ciao, ho lo stesso problema di Io, c’è qualche soluzione a riguardo? Mi serverebbe veramente molto questo plugin….
Grazie per l’aiuto …
Per favore…?
Question:
I’m using the plugin on a testing subdomain and when I set the first attribute to “true” none of my images will show. But when I change to false, all the images immediately show, although since I have them set to resize they are becoming a bit distorted.
I do indeed have the gd2 graphics plugin for PHP. I double checked with my host this evening.
Funny thing is, I’m using same plugin on the root domain of another site (hosted on same host) and it works fine when set to “true”.
Any suggestions?
I had the same problem as Lindsey and a few others here when using the wonderful Image Extractor plugin on a WordPress site in a subfolder.
Solution:
When entering your path in the imageExtractor.php, make sure you add the subfolder path in the beginning. For example for a site: http://www.mysite.com/subfolder and thumb-folder with correct permissions at wp-content/thumb it is:
$destinationDir=”/subfolder/wp-content/thumb
Works perfectly.
I had a similar problem where resized images weren’t working, the thumbnail wasn’t being created in the cache file, when I moved hosting. I finally tracked down the problem to the plugin using DOCUMENT_ROOT which was giving the wrong result, I changed it to use PHP_DOCUMENT_ROOT and it all works fine again. Hope this info may help someone else having problems.
Thanks a lot for the plugin. It modified my blog nicely.
However, you need to modify details of your plugin on wordpress site as it has the wrong syntax. imageextractor rather then image_extractor.
Cheers,
pluzz
This is a really good plugin
Hey, nice plugin. But I’m confused as to how to implement this on my blog.
I’m using the livewire theme. Can you help me out?
Is it possible to make this plugin work for external images ?
ciao, mi scuso per l’intrusione ma ho bisogno di aiuto e sono davvero in difficoltà.
Mi spiego: fino a pochi giorni fa usavo la plugin “alakhnors-post-thumb” ma non so bene per quale motivo ha fatto esplodere il blog, ed è il caso di usare questo termine, visto che ha buttato giù il server aruba per 3 giorni
Però tante mi piacerebbe avere nella sidebar sx le iconcine delle foro degli ultimi 10 post con i relativi titoli lincati.
Cosa posso fare?
Non posso permettermi di buttare di nuovo giù il server aruba, hanno minacciato di sospendere il contratto!
Questa plugin fa al caso mio ed è compatibile con WP 2.7.x?
grazie con tutto il cuore per tutto l’aiuto che riuscirai a darmi
how would i make it get thumbnails from images on my category page?
thnx for the plugin but how to make it to resize all images that I post from other sites not uploaded to wordpress… Can I resize that kind of images or not.. Please answer soon because I need it very much
Hi,
Is there a way to override img tag attributes “alt” and “title” with the title of the post which the image is extracted from?
cheers,
valix
For anyone having the problem of no images showing up, here is a possible solution (works on Mosso.com cloud hosting with WordPress 2.7.1)
Edit the file: imageExtractor.php
Find all instances of: getenv(“DOCUMENT_ROOT”)
and replace with: $_SERVER["PHP_DOCUMENT_ROOT"]
Apparently on _some hosts_, DOCUMENT_ROOT doesn’t come through as the correct place on the server to put the files, so the plugin fails to create the thumbnails.
Stef
hi
i am getting below error once i activate plugin
Fatal error: Class ‘htmlparser’ not found in D:\training\wamp\www\wordpress\wp-content\plugins\image-extractor\imageExtractor\imageExtractor.php on line 91
please help me out how to solve this issue
sto avendo dei problemi a far girare il plugin su un server windows.
quando lo attivo mi appare un sacco di codice, faccio fatica a capire qual’è l’errore.
help!
il codice che mi appare è questo: html = “”; $this->html=$htmlcode; return true; } function LoadHTML($filename) { $this->html = “”; if (!file_exists ($filename)) { //return false; } //$filename=”http://www.dynamick.it”; //echo $filename.”"; $fh = @fopen (trim($filename), “r”); if ($fh!=false) { //flock($fh,2); while (!feof ($fh)) { $buffer = fgets($fh, 10240); if ($buffer!=”") { $this->html.=trim($buffer); } } //flock($fh,3); fclose($fh); return true; } else return false; } function GetElements(&$result) { if (count($this->elements)==0) { return false; $result=array(); } $result=$this->elements; return true; } function Parse() { $ignorechar = false; $intag = false; $tagdepth = 0; $line=”"; $text=”"; $tag=”"; if ($this->html==”") { return false;} $raw = split (“\r\n”, $this->html); while (list($key, $line) = each ($raw)) { $htmlline = htmlentities($line); if ($line==”") { continue; } $line = trim($line); for ($charsindex=0;$charsindex<=strlen($line);$charsindex++) { if ($ignorechar==true) { $ignorechar=false;} if (($line[$charsindex]=="elements[]=$text; $text=”"; } $intag = true; } else if (($line[$charsindex]==”>”) && ($intag)) { $tag .=”>”; /* Tag Found */ $this->elements[]=$tag; $ignorechar = true; $intag=false; $tag=”"; } if ((!$ignorechar) && (!$intag)) { $text .= $line[$charsindex]; } else if ((!$ignorechar) && ($intag)) { $tag .= $line[$charsindex]; } } } return true; } function download($file_source, $file_target) { $rh = @fopen($file_source, ‘rb’); $wh = fopen($file_target, ‘wb’); if ($rh===false || $wh===false) { return true; } while (!feof($rh)) { if (fwrite($wh, fread($rh, 1024)) === FALSE) { echo ‘Download error: Cannot write to file (‘.$file_target.’)'; return true; } } fclose($rh); fclose($wh); return false; } function getAttributes($html) { //preg_match_all(‘/(\w+\s*=\s*”[^"]*”)*|(\w+\s*=\s*\’[^\']*\’)*/’,$html,$attr); $attrWithDblQuote=’((\w+)\s*=\s*”([^"]*)”)*’; $attrWithQuote=’((\w+)\s*=\s*\’([^\']*)\’)*’; $attrWithoutQuote=’((\w+)\s*=(\w))*’; preg_match_all(‘/’.$attrWithDblQuote.’|’.$attrWithQuote.’|’.$attrWithoutQuote.’/',$html,$attr); //echo “#
“;print_r($attr);echo ”
“; if (is_array($attr)) foreach ($attr as $count=>$attrArr) { if (is_array($attrArr)) foreach ($attrArr as $i=>$a) { if ($a!=”" and $count==2) $res[$a]=$attr[3][$i]; if ($a!=”" and $count==5) $res[$a]=$attr[6][$i]; if ($a!=”" and $count==8) $res[$a]=$attr[9][$i]; } } return $res; } function linkAnalyzer($url) { $regexp = “(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?”; $regexp = “(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?”; eregi($regexp,$url,$ret); $r["url"]=$url; $r["scheme"]=$ret[2]; $r["authority"]=$ret[4]; $r["path"]=$ret[5]; $r["query"]=$ret[7]; $r["fragment"]=$ret[9]; return $r; } function getTagResource($tag=”a”) { global $elements; $tag=”elements)){ if (strtolower(substr($code,0,strlen($tag)))==$tag) { $attribArr[]=$this->getAttributes($code); } } return $attribArr; } function includeImportCss($html,$path=”",$level=1) { global $urlToGrabArr; preg_match_all(‘/@import\s[\"]*((http:\/\/[^\/]*){0,1}(.*?))[\"]{0,1};/i’, $html,$result); //echo ”
#”.dirname($path).”#
“;print_r($result);echo ”
“;die; if (is_array($result[3])) foreach ($result[3] as $k=>$v) { $url=dirname($path).”/”.$result[3][$k]; //echo “url ricavato: $url
“; if ($this->url_exists($url)) { $css=@file_get_contents($url); //die ($css); $html=preg_replace(‘/@import\s[\"]*((http:\/\/[^\/]*){0,1}(.*?))[\"]{0,1};/i’, $css, $html); //if (strstr($html,”@import”)) $html=importCss($html,dirname($result[3][$k]),$level++); } } return $html; } function url_exists($url) { $handle = @fopen($url, “r”); if ($handle === false) return false; fclose($handle); return true; } } ?>
Il fix suggerito per evitare il problema di cropping funziona:
[code]
$thumbnail->setResizeMethod('workaround');
[/code]
change it to this:
[code]
$thumbnail->setResizeMethod('resize');
[/code]
Grazie, ottimo plugin, gira bene sulla 2.8
Hi,
Image extractor is a great plugin but it doesnt currently work for my site.
What happens is that for my blog template, on each of my posts, i have a bunch custom fields, one of them is called “img” where i put the url of the image i want to be displayed in my post. However Image Extractor doesnt take images in the custom fields in consideration, because they are not actually in the of the post’s wysiwyg “content”.
The workaround for this is for me to post the image once in the wysiwyg, with a css class that hides the image, and then put the img url again in the “img” custom field that i use for my blog post templates. This is rather annoying and defeat the purpose of this plugin.
So my question is this, is there a way for Image Extractor to be aware of the images in the post that are inserted with the custom fields ???
Buongiorno, a me viene fuori questo errore
Warning: imagejpeg() [function.imagejpeg]: Unable to open ‘/www/www/mat/thumb/72×73-foto021-150×150.jpg’ for writing in /www/www/ivan/ivan-wordpress/wp-content/plugins/imageExtractor/class.ImageToolbox.php on line 679
non sono molto esperto non so che fare
Ah ho risolto, sbagliavo nel cambiare il path delle immagini /math/thumb, ora ho corretto.
guys, does anybody know how to change color from “white” to another, e.g. black..?
To lo, ale and anybody else who’s getting the:
html = “”; $this->html=$htmlcode; return true; } function LoadHTML($filename)
error.
Try to edit the htmlParser.php file inside imageExtractor dir and check 1st line: if it’s
<?
change it to:
<?php
This worked for me in my WAMP environment.
Nonostante la sua età, funziona ancora a meraviglia!
Ciao Mick, avrei da farti un domandone: è possibile integrare il plugin “NextGen Gallery” con image extractor? Le immagini che vengono caricate su nextgen hanno una cartella di destinazione finale differente (/wp-content/gallery/) rispetto a quella dell’extractor (/mat/thumb/). E’ possibile dargli in pasto anche la cartella gallery?
Certo che si può, basta metter mano ad una variabile all’interno del plugin di Image Extractor. Però non conosco così bene NextGen Gallery per poter dirti che vengono caricate anche nella galleria. Ciao!
hellow
how can i make the thumbnails just smaller than the original post without cropping and changing the form of the image
thx
@degreef wesley: Yes, u can. U have just to change the resizing method.
Hello. This may be an odd question but a situation has arisen that has made it such that I must extract/resize the first image in a post then display X number of other images as normal. My first image is being resized no problem but none of the other images show up. Can I override this by chance? Any way of showing the other images untouched?
Hello Mike,
thanks for this great plugin! I have a question:
Is it possible to positioning the image at the top and not to the center, if the image is filled with whitespace because of correct aspect ration? Thanks.
Hi Thomas,
honestly I do not have any ideas if it could be possible.
The plugin uses Image Toolbox, an image manipulation library.
You could study this file
http://image-toolbox.sourceforge.net/docs/Image_Toolbox/_Image_Toolbox_Image_Toolbox_class_php.html
to find what you are searching.
Cheers,
Mick
Sorry, I mean of course Mick
[...] ————————- often people just want to remove the first image in a post, with the above script, this is how. <?php ob_start(); the_content(‘Read the full post’,true); $postOutput = preg_replace(‘/]+./’,”, ob_get_contents(),1); ob_end_clean(); echo $postOutput; ?> —————————– <?php $beforeEachImage = “<div>”; $afterEachImage = “</div>”; preg_match_all(“/(<img [^>]*>)/”,get_the_content(),$matches,PREG_PATTERN_ORDER); for( $i=0; isset($matches[1]) && $i < count($matches[1]); $i++ ) { echo $beforeEachImage . $matches[1][$i] . $afterEachImage; } ?> ——— http://www.dynamick.it/image-extractor-765.html [...]
For those who have this problem:
Fatal error: Image: Imagetype (jpg) not supported for reading
This is due to a php version >5.3.
Fix this error by patching the class.ImageToolbox.php. Replate the line 203:
if ($gd_info['JPG Support']) {
with this:
if ($gd_info['JPG Support'] or $gd_info['JPEG Support']) {
Hope this could help u…
Cheers
Nice Post. Thanks!
Sir, can you please explain how to change the output files to jpg?
I use this code on my home page (as part of Visual Recent Posts) and the png thumbnails are too large. Thanks!
Open the imageExtractor.php file (you find in the wp-content/plugins/imageExtractor/) and edit the line 116.
Change the following code:
$thumbnail->save(getenv(“DOCUMENT_ROOT”).$dest,”png24″);
with:
$thumbnail->save(getenv(“DOCUMENT_ROOT”).$dest,”jpg”);
where the change is the text “jpg” instead of “png24″.
Hope this could help you.
lovelty tool and a great website too !
Does this plugin only resizes the original image or it also crops it according to the size…?
Both, depends on the resize_type parameter. 2 and 0 resize, 1 crop the image.
Hello,
Today I enabled WP_DEBUG on my wp-config.php file and I’m getting thousands of Uninitialized string offset errors in htmlParser.php.
Actually it’s a loop of these 3 errors below:
PHP Notice: Uninitialized string offset: 171 in /var/www/html/wp-content/plugins/imageExtractor/htmlParser.php on line 115
PHP Notice: Uninitialized string offset: 171 in /var/www/html/wp-content/plugins/imageExtractor/htmlParser.php on line 126
PHP Notice: Uninitialized string offset: 171 in /var/www/html/wp-content/plugins/imageExtractor/htmlParser.php on line 138
What those lines have in common is $line[$charsindex] but I’m a complete PHP n00b so I don’t know what to do to fix this.
Any ideas?
Thanks!
That are “notices” and they aren’t “errors”. The messages mean that a variable wasn’t initialized ($variable = “” ), but the script could run anyway.
Is there any code to extract the videos from post which i have embed through “Viper’s Video Quicktags” plugin
Thank you Mick !!