Check how many pages are included in a multi-page image file with GraphicsMagick - graphicsmagick

Is there a way to determine in advance how many pages are included in a multi page tif image with GraphicsMagick ?
I know I can select the first page in this way : image.tif[0], and probably iterating the array until the command fail will return the last image, but I don't think this is the best approach.

You can get a numbered list of the pages with
gm identify image.tif
and look at the last line, or count the lines. The images are numbered 0 thru N -1.

It is not too late to answer.
I think it is not possible to get the page count beforehand, not even with libtiff.
However, you can avoid the trial and error by using Magick::readImages:
// Magick++
std::vector<Magic::Image> images;
Magick::readImages(&images, "multipage.tif");

Related

Querying Two Wordpress Categories via URL

I have posts that are assigned to two categories let's say cars and paints. I'm trying to only get posts that are in both, the following code http://example.com/category/cars+paints is supposed to work according to this article but it doesn't and I get a page saying The requested document was not found on this server. When I try http://exapmle.com/category/cars,paints it works but it gives me too many posts.
It seems that & is supposed to work as well, I tried http://exapmle.com/category/cars&paints and http://exapmle.com/category/?cat=cars&cat=paints but this doesn't either work, I don't know if I have the syntax wrong.
When I try http://exapmle.com/?cat=1&cat=2 using the category IDs it directs to a page like this http://exapmle.com/category/paints with the last parameter corresponding to the last number entered in the URL.
Does anyone know why it's not working and what I can do to get it to work, thanks in advance.
Changing the + to a space %20 seems to be working for me
Example:
http://example.com/category/cars%20paints

How to hide an item on a report?

I did some changes one of the method on accounting report in OpenERP. My problem now is how can i make some item invisible or delete? In particular, I want to hide the "Liability" and its balance on the report.
I tried something like this on get_lines method:
for report in lines:
if report["name"].lower().replace(" ","") == 'liability':
del report["name"]
del report["balance"]
but when i tried to generate Balance sheet report. It says:
(<type 'exceptions.KeyError'>,KeyError('name',), <traceback object at 0x7f6c4c2903f8>)
Any help is much appreciated.
This is an error that raises when you try to access object key that doesn't exist. In your case "name".
Error you have is "logical" error, simply go into debug and see what you get in report variable inside loop.
Moreover, to change report content (and by report I think you mean pdf output right?) you need to override .rml file. I think you are changing report parser here, which is also ok if you know what you are doing.
Here you can find RML documentation: http://www.reportlab.com/docs/rml2pdf-userguide.pdf
So, to sum: to change report output content override or replace parser, to change structure, hide/add fields override existing report (.rml file) or create entirely new report.
Hope it helped :)
This might not be the good (or perhaps the weirdest) solution to the problem but after reading about .rml and i can't still comprehend this is what i did. Instead of trying to delete report["name"] and report["balance"] i just set it's value into a white space. This time it's no longer shown on the report.

Simian multiple excludes option

I use Simian to analyze the duplicate codes in my c# project.
But I want to exclude two kind of situations.
One is unit test files shouldn't be analyzed, the other is auto-generated file (such as Microsoft.Moles auto produces m.g.cs files)
My arguments are fine as following when I only have one kind of file excludes
-formatter=vs:c:\temp\SimianResult.log -language=cs $(SolutionDir)//*.cs -excludes=/*Test.cs -threshold=15
But when I add the second situtions, I don't know how to put them together, I search it on the web ,but cannot find samples, even the offical site http://www.harukizaemon.com/simian/ doesn't show it.
I try the following combination but all fails
(1)... -excludes=/*Test.cs,/*m.g.cs -threshold=15
(2)... -excludes=/*Test.cs;/m.g.cs -threshold=15
(3)... -excludes=*/Test.cs */*m.g.cs -threshold=15
Does anybody know how to solve it ?
thanks
My co-worker has try the correct syntax for me and it works.
The key is your have to put the keyword "excludes" twice. So the answer of my question is
-formatter=vs:c:\temp\SimianResult.log -language=cs $(SolutionDir)//*.cs -excludes=/Test.cs -excludes=*/m.g.cs -threshold=15

avoiding XDMP-EXPNTREECACHEFULL and loading document

I am using marklogic 4 and I have some 15000 documents (each of around 10 KB). I want to load the entire content as a document ( and convert the total documents to a single csv file and output to HTTP output stream for downloading). While I load the documents this way:
let $uri := cts:uri-match('products/documents/*.xml')
let $doc := fn:doc ($uri)
The xpath has some 15000 xmls. So fn:doc throws an error XDMP-EXPNTREECACHEFULL.
Is there any workaround for this? I cannot increase tree cache size in admin console because the number of xml files in products/documents/*.xml may increase.
Thanks.
When you want to export large quantities of XML from MarkLogic, the best technique is to write the query so that results can stream, avoiding the expanded tree cache entirely. It is a very different style of coding, though: you'll have to avoid strong typing of any kind, and refactor your code to remove FLWOR expressions. You won't be able to test any of the code in cq or qconsole, either.
Take a look at http://blakeley.com/blogofile/2012/03/19/let-free-style-and-streaming/ for some tips on how to get there. At a minimum the code sample you posted would have to become:
doc(cts:uri-match('products/documents/*.xml'))
In passing I would try to rework that to avoid the *.xml part, because it will be slower than needed. Maybe something like this?
cts:search(
collection(),
cts:directory-query('products/documents/', 'infinity'))
If you need to test for something more than the directory, you could add a cts:and-query with some cts:element-query test.
For general information about this error, see the MarkLogic knowledge base article on XDMP-EXPNTREECACHEFULL

Addiing captions above images in wordpress

So I added some code in my css and there are boxes that appear over every image that is attached to a post. I've wanted to number the images and show the image number in the box(1...n). I have this in my functions.php
edit: code was added here http://pastebin.com/gVszwf75
If I run only count_images it will show the correct number of attached images to a post(let's say 15). But for some reason the number that is shown in the boxes over the images is always 1. I've seen this done on several blogs with just php so there has to be a way(even if I have to change my whole code).
The problem with your code is that you're looping through the array each time you call your callback function caption_image_callback() ... it has no memory of how many times it's looped!
The easiest way to fix this is to add a global variable at the beginning of the plug-in, I call it $caption_image_count and set it equal to zero. Then call the variable in caption_image_callback() and increment by 1 each time you call the function. This will keep track of the number of captioned images you have on the page.
If you want, you can also re-set the variable to zero before you return $post_body_content in caption_image(). I've posted the full solution to your pastebin: http://pastebin.com/sFe6dhqL

Resources