Advertisement

07.08.2008 at 10:36PM PDT, ID: 23549153
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.6

PHP script using the Imagick module

Asked by SWB-Consulting in Scripting Languages, PHP Scripting Language, ghostscript Font Software

I have a function that creates a preview of a PDF file.

I attached the function, it only works under windows (after installing Imagick for Windows, GhostScript for Windows and adding the extension "php_imagick_dyn-Q16.dll" to PHP).

My questions, is there any equivalent to "php_imagick_dyn-Q16.dll" for linux so that I can still use the same function in a linux server?

If not, how would be the function using the original PHP's module Imagick (http://www.php.net/imagick)?Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
/**
 * 
 */
function createPreview($_file, $_noise_image) {
	// create handle for new PDF document
	$pdf_handler = pdf_new();
	// open a file
	pdf_open_file($pdf_handler, dirname($_file) . "/" . "preview_" .  basename($_file));
	// insert the previews
	$images = new Imagick($_file);
	//
	foreach ($images as $k => $image) {
		
		/****************************************
		 * THE NOISE
		 ***************************************/
		 
		// Get original size of image
		$height = $image->getImageHeight();
		$width = $image->getImageWidth();
		
		// We need an overlay ~66% of the image
		$o_height = floor(2*($height) / 3);
		 
		// Grab region of the image and make into a new Imagick class
		$im_overlay = $image->getImageRegion($width, $o_height, 0, $height - $o_height);
		 
		// Do obfuscating effect.
		$im_overlay->blurImage(5,6);
		//$im_overlay->addNoiseImage(imagick::NOISE_LAPLACIAN);
		 
		// Overlay images
		$image->compositeImage($im_overlay, imagick::COMPOSITE_OVER, 0, $height - $o_height);
		
		// Comment : I almost forgot the text overlay. Just add this after:
		// image->compositeImage($im_overlay, imagick::COMPOSITE_OVER, 0, $height - $o_height);
		
		/****************************************
		 * THE PREVIEW TEXT
		 *************************************/
		
		 // Do preview text
		$draw = new ImagickDraw();		 
		// Set font soze
		$draw->setFontSize(52);		 
		// Align text to center
		$draw->setTextAlignment(imagick::ALIGN_CENTER);		 
		// Initialize color class
		$black = new ImagickPixel();
		$black->setColor('black');		 
		// Set text color
		$draw->setFillColor($black);		 
		// Draw text in middle of image (within 66%)
		$draw->annotation(floor($width / 2), floor($height / 2), 'PREVIEW');		 
		// Overlay text
		$image->drawImage($draw);
		
		
		/******************************
		 * CREATE THE IMAGE
		 ****************************/
 
		// Write out image, go on.
		$preview_jpeg =  dirname($_file) . "/" . "tmp_page" . $k . '_.jpg';			
		$image->setImageFormat("jpg");	
		$image->writeImage($preview_jpeg);	
		
		// start a new page (A4)
		pdf_begin_page($pdf_handler, 595, 842);
		$pdfimage = pdf_load_image($pdf_handler, "jpeg", $preview_jpeg, "");	
		pdf_place_image($pdf_handler, $pdfimage, 0, 0, 1);
		
		// end page (A4)
		pdf_end_page($pdf_handler);		
		// clean
		@unlink($preview_jpeg);
		//$image->clear();
		//$image->destroy();
	}
	// close and save file
	pdf_close($pdf_handler);
}
[+][-]07.08.2008 at 10:58PM PDT, ID: 21960905

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.08.2008 at 10:59PM PDT, ID: 21960912

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.08.2008 at 11:00PM PDT, ID: 21960915

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.08.2008 at 11:04PM PDT, ID: 21960927

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Scripting Languages, PHP Scripting Language, ghostscript Font Software
Sign Up Now!
Solution Provided By: Lordgobbledegook
Participating Experts: 2
Solution Grade: B
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628