Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
J Crewl
Dec 11, 2005
Stupid newbie question here. Is there anything inherently wrong with the below statement, or do I need to include more of a context?
code:
$db->query('INSERT INTO '.$db->prefix.'geocoordinates (name, latitude, longitude)VALUES
(\\''.$db->escape($name).'\\', \\''.$db->escape($latitude).'\\', \\''.$db->escape($longitude).'\\')') 
or error('Unable to insert geocode', __FILE__, __LINE__, $db->error());
Where name, latitude, and longitude are strings that I'm sure have value since I echo them before this. They are also all varchars in mysql db. The only other field in the table is an auto-incremented Id.

Is the problem in the syntax or is it something in my logic?

It only outputs the "unable to insert geocode" with no specific error to work off of.

J Crewl fucked around with this message at 01:26 on Mar 31, 2008

Adbot
ADBOT LOVES YOU

functional
Feb 12, 2008

That code is hard to read. Why don't you escape your variables before constructing your query string?

waffle iron
Jan 16, 2004
I would either:

A) Use a database abstraction layer with prepared/parametrized queries so you don't have to do the escaping manually or
B) Break the string concatenation on to another line and assigned it to a variable with some line breaks/formatting around the . operator.

such a nice boy
Mar 22, 2002

J Crewl posted:

Stupid newbie question here. Is there anything inherently wrong with the below statement, or do I need to include more of a context?
code:
$db->query('INSERT INTO '.$db->prefix.'geocoordinates (name, latitude, longitude)VALUES
(\\''.$db->escape($name).'\\', \\''.$db->escape($latitude).'\\', \\''.$db->escape($longitude).'\\')') 
or error('Unable to insert geocode', __FILE__, __LINE__, $db->error());

When you have a problem like this, you want to know exactly what query you're sending to the database. If you have that, you can put it into the DB shell manually and the DB will helpfully spit out an error that hopefully tells you what's wrong.

So you take the query, stick it in a variable (perhaps $query), print that variable out, and then run the query on that variable. To wit:

code:
$query = 'INSERT INTO '.$db->prefix.'geocoordinates (name, latitude, longitude)VALUES
(\\''.$db->escape($name).'\\', \\''.$db->escape($latitude).'\\', \\''.$db->escape($longitude).'\\')';
print $query;
$db->query($query) or error('Unable to insert geocode', __FILE__, __LINE__, $db->error());
There are certainly other sucky things about that code, though. Constructing table names dynamically is bad. I don't know what those \\ guys are there for; is that for escaping something? The "$db->escape()" function probably does that for you. And using string concatenation to build a query is bad form, anyway. The pros use database abstraction layers, and the totally awesome ones use ORMs.

Lankiveil
Feb 23, 2001

Forums Minimalist
I'm trying to put together a text comparison tool, that will compare two strings (more than likely containing largish volumes of fulltext), and show the different, something like Wikipedia's diff functionality.

Doing a simple character-by-character comparison will not work, because the first "new" character in a string will push all the others forward, causing almost everything after that point to be highlighted. Tokenising the string seems to be the way forward, but I can't work out a good way of comparing that doesn't "match" completely unrelated words later on in the text.

Is there an accepted way of doing this, or am I going to need to invent some new kind of wheel?

Atom
Apr 6, 2005

by Y Kant Ozma Post
Wikipedia is opensource, why not just look at the subroutines that handle diff straight from the horse's mouth?

minato
Jun 7, 2004

cutty cain't hang, say 7-up.
Taco Defender
Or just use exec() or something to run diff directly (assuming your host is running Linux).

diff is a pretty clever program, I wouldn't want to be re-inventing that unless I absolutely needed to.

Foolio882
Jun 16, 2003

by Fistgrrl
I'm back, this time header() is giving me hell()

php:
<?php header('Content-type: image/jpeg');?>
<html>
<body>
<?php
//functions.inc contains displayPictureTable()
include("functions.inc");
//displayPictureTable works correctly up until picture output
displayPictureTable(shedsgable);
?>
</body>
</html>
Hopefully this one is as simple as the last time, but I just cannot figure out why this won't work.

My function displayPictureTable() works as it should as this all currently sits. It outputs my two test echos, and then attempts to output the picture I have designated but instead of pretty colors, I only get gibberish:

code:
CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality ÿÛC    
$.' ",#(7),01444'9=82<.342ÿÛC  2!!22222222222222222222222222222222222222222222222222ÿÀ– ...and on and on and on
Here are the steps I have gone through:

1) No header(), gibberish.
2) Put header() in the wrong spot, error message and gibberish
3) [Where I am now] I have header() in what I believed to be the correct location, am getting no error messages (E_ALL), but I'm still not getting a picture.

I'm certain this is another stupid mistake (hopefully) common amongst those of us new to php, but I just can't pinpoint what the hell is going wrong here :(

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Uh, you're outputting text instead of an image. Get rid of that html nonsense.

MrEnigma
Aug 30, 2004

Moo!

duz posted:

Uh, you're outputting text instead of an image. Get rid of that html nonsense.

or move the header right before it. One other piece of advice, usually you want your functions to always return data, instead of printing it out. And then do a print/echo/whatever on on the function on your page.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


MrEnigma posted:

or move the header right before it. One other piece of advice, usually you want your functions to always return data, instead of printing it out. And then do a print/echo/whatever on on the function on your page.

You can't send headers after outputting content.

Foolio882
Jun 16, 2003

by Fistgrrl

duz posted:

You can't send headers after outputting content.

True, but getting rid of my "html nonsense" changes nothing as well:

php:
<?php header('Content-type: image/jpeg');
 
include("functions.inc");
 
displayPictureTable(shedsgable);
 
?>

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


That's because you're still outputting text instead of the image your header is telling the browser to expect.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Foolio882 posted:

True, but getting rid of my "html nonsense" changes nothing as well:

php:
<?php header('Content-type: image/jpeg');
 
include("functions.inc");
 
displayPictureTable(shedsgable);
 
?>


What exactly does displayPictureTable spit out? You can't output any text or html with that header set.

admiraldennis
Jul 22, 2003

I am the stone that builder refused
I am the visual
The inspiration
That made lady sing the blues

Foolio882 posted:

True, but getting rid of my "html nonsense" changes nothing as well:

php:
<?php header('Content-type: image/jpeg');
 
include("functions.inc");
 
displayPictureTable(shedsgable);
 
?>


You clearly have some fundamental misunderstandings here.

What are you trying to accomplish? What does displayPictureTable output?

By specifying a content-type of image/jpeg, you are telling the browser that the entire document you are producing is a jpeg image. The only output should be binary image information, such as that outputted by gd's image creation functions.

You can't simply spit the binary contents of an image from a gd function into the middle of an html document and expect an image to appear.

Foolio882
Jun 16, 2003

by Fistgrrl

fletcher posted:

What exactly does displayPictureTable spit out? You can't output any text or html with that header set.

Oh dear god I think I'm hosed, as the function name suggests, this is supposed to be outputting a picture table and it's loaded with required html.

Is there any way to mix html and php to output a table of pictures? I'd like to avoid iterating through the directory to display them as html pictures, as I need the displayed pictures to be thumbnail links to fullsize pictures.

Something like this would work, but be a complete and total pain in the rear end:

php:
<?
$directory = opendir($picPath);

while($fileName = readdir($directory)) {
    $dirArray[] = $fileName;
}

//Here display $picPath/thumbs/$dirArray[1,2,...n] as links to $picPath/$dirArray[1,2,...n]
?>
You see my anger, I'd then have to make sure all the file names were identical and have to create a thumbnail every time we want to add a picture to the table as opposed to just uploading it at the correct resolution into one folder and dynamically resizing it.

This is going to suck.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Foolio882 posted:

Is there any way to mix html and php to output a table of pictures?

Like this?

code:
<table>
<?php
for ($i=0;$i<sizeof($whatever);$i++) {
echo '<tr><td><img src="'.$whatever[$i].'"></td></tr>';
}
?>
</table>
If you want thumbnails created automatically, when you read the directory of pictures also look or the <filename>_thumbnail.jpg, if it's not there, then create it, save it, and move on. You can use GD (built into PHP) to resize the images. I'm still kinda confused on what you are trying to do though.

Foolio882
Jun 16, 2003

by Fistgrrl

fletcher posted:


If you want thumbnails created automatically, when you read the directory of pictures also look or the <filename>_thumbnail.jpg, if it's not there, then create it, save it, and move on. You can use GD (built into PHP) to resize the images. I'm still kinda confused on what you are trying to do though.

But that's what I am trying to avoid, having seperate thumbnails.

Here's the ultimate goal:

1) A potential customer comes to our website, and is interested in a Shed, Deck, or Gazebo, and would like to see some of our recent projects.

2) They somehow navigate to the "Sheds" section of recent projects, and want to see, for example, Gable style sheds that we have built.

3) Some time before this, someone has put a whole bunch of pictures into ./images/sheds/gable

4) On recentprojects/sheds/gable.php (Or whatever it may be, I don't care) this potential customer will see a table (looks aside, that's not my job) of thumbnails for every picture in ./images/sheds/gable/

5) Each thumbnail is a link to a full size picture opening in a new window.

6) And then we somehow get another building to stand upright (Call it a gazebo), photograph it, throw it into ./images/gazebos and it's a new addition to recentprojects/gazebos.php (Just sitting there pretty at the end of the line, nothing fancy)

I can do this all day long (and in fact did, as proof of concept) with seperate directories for thumbs and full size images, but thats just not the way I'd like to go if at all possible.

edit: I just re-read your post. Are you suggesting the code do these steps:?

1) Get list of filenames in, for example, ./images/decks
2) Check if $dirArray[0] exists in ./images/decks, output with html if YES
3) If NO, create thumbnail, save. Output with html.
4) repeat.

That makes sense to me, but I'm not sure how to use gd to actually create a new *.jpg int he event of a missing thumbnail.

Foolio882 fucked around with this message at 21:54 on Mar 31, 2008

admiraldennis
Jul 22, 2003

I am the stone that builder refused
I am the visual
The inspiration
That made lady sing the blues

Foolio882 posted:

Oh dear god I think I'm hosed, as the function name suggests, this is supposed to be outputting a picture table and it's loaded with required html.

Is there any way to mix html and php to output a table of pictures? I'd like to avoid iterating through the directory to display them as html pictures, as I need the displayed pictures to be thumbnail links to fullsize pictures.

Something like this would work, but be a complete and total pain in the rear end:

php:
<?
$directory = opendir($picPath);

while($fileName = readdir($directory)) {
    $dirArray[] = $fileName;
}

//Here display $picPath/thumbs/$dirArray[1,2,...n] as links to $picPath/$dirArray[1,2,...n]
?>
You see my anger, I'd then have to make sure all the file names were identical and have to create a thumbnail every time we want to add a picture to the table as opposed to just uploading it at the correct resolution into one folder and dynamically resizing it.

This is going to suck.

Web browsers request and load images separately from HTML.

I'd probably stick the resize image code in another php script; let's call it makeThumb.php for example. makeThumb.php takes in an image filename via GET and outputs the resized version.

The displayPictureTable function would output a table containing HTML that refers to images generated by makeThumb.php, for example:
php:
<?
foreach($imgarray as $img) {
    echo "<img src=\"makeThumb.php?img={$img}\"><br>";
}?>
Of course, dynamically resizing all the displayed images every time the page loads is going to be slow as all gently caress, so I'd probably have makeThumb cache the thumbnails we've already created.

An elegant solution might include <img> tags that refer to images directly as if they already existed in a thumbnail directory (e.g. <img src="/img/thumbs/pic1.jpg">). If the appropriate thumbnail already exists, it will be loaded per normal. If not, a simple 404 redirection could point to a thumbnail generation script that would fetch the original image ('/img/pic1.jpg'), return the resized one to the browser, and then store the resized one in the thumbs for later use.

admiraldennis fucked around with this message at 22:01 on Mar 31, 2008

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Foolio882 posted:

But that's what I am trying to avoid, having seperate thumbnails.

You can use width and height on the <img> tag (which is a horrible way to do it) otherwise you are going to have to create separate thumbnails. Why is that such a bad solution if it's done automatically?

Foolio882
Jun 16, 2003

by Fistgrrl

fletcher posted:

You can use width and height on the <img> tag (which is a horrible way to do it) otherwise you are going to have to create separate thumbnails. Why is that such a bad solution if it's done automatically?

If it can be done automatically, I'm all for it and that will work just fine and dandy. I just did a bit of quick googling and found some very relevant information, and hopefully this will all come together nicely.
(Read: I'll be back later with more awful questions, but you all have been very helpful and I do appreciate it!)

admiraldennis
Jul 22, 2003

I am the stone that builder refused
I am the visual
The inspiration
That made lady sing the blues

Foolio882 posted:

If it can be done automatically, I'm all for it and that will work just fine and dandy. I just did a bit of quick googling and found some very relevant information, and hopefully this will all come together nicely.
(Read: I'll be back later with more awful questions, but you all have been very helpful and I do appreciate it!)

Yeah, this is all pretty basic knowledge stuff.

Did you read/comprehend my post?

Foolio882
Jun 16, 2003

by Fistgrrl

admiraldennis posted:

Yeah, this is all pretty basic knowledge stuff.

Did you read/comprehend my post?

What can I say, I'm new to this stuff :v:

And yes, it all made sense to me, mostly. Would using GET and that makeThumb.php script you suggested work just as well for the one time "Oops, we don't have a thumbnail!" moments?

The one part of your post I didn't fully comprehend was "a simple 404 redirection could point to a thumbnail generation script that would fetch the original image ('/img/pic1.jpg'), return the resized one to the browser, and then store the resized one in the thumbs for later use. " I understand the goal there, and think it would work very well, but can you clarify what I've bolded? Is that what you already talked about with the makeThumb.php script?

admiraldennis
Jul 22, 2003

I am the stone that builder refused
I am the visual
The inspiration
That made lady sing the blues

Foolio882 posted:

The one part of your post I didn't fully comprehend was "a simple 404 redirection could point to a thumbnail generation script that would fetch the original image ('/img/pic1.jpg'), return the resized one to the browser, and then store the resized one in the thumbs for later use. " I understand the goal there, and think it would work very well, but can you clarify what I've bolded? Is that what you already talked about with the makeThumb.php script?

By "a simple 404 redirection" I meant a system to redirect 404 errors that occur during requests to documents the thumbs directory to a specific php script. If the server was apache, you'd place an .htaccess file in the '/img/thumbs/' directory containing something like:
code:
ErrorDocument 404 /makeThumb.php
That will redirect all 404 (resource not found) errors that occur in that directory to /makeThumb.php. If you request '/img/thumbs/boon.jpg' and boon.jpg exists, it will be returned. If boon.jpg does not exist, it will load makeThumb.php, which will do the following:

  • parse the filename (boon.jpg) out of the request uri (/img/thumbs/boon.jpg)
  • look for the original image file at /img/boon.jpg
  • if the image is not found, display a prepared error image and exit. otherwise, if the image exists, continue on...
  • load and resize the original image
  • display the resized image (use an image content-type and output)
  • store the resized image as a file at /img/thumbs/boon.jpg
A potential flaw in the above is that changing the source images will not update the thumbnails. Your best solution for that is probably either hashing or moddate checking (you'd have to be very careful with the latter but it would be faster).

admiraldennis fucked around with this message at 22:58 on Mar 31, 2008

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
What's a clean/efficient way to do bbcode replacements for format tags like [b], [i], etc?

Begby
Apr 7, 2005

Light saber? Check. Black boots? Check. Codpiece? Check. He's more machine than kid now.

fletcher posted:

What's a clean/efficient way to do bbcode replacements for format tags

This has been done a lot. It would probably be a good idea to check out the source for a php package that has already implemented this.

On the surface it looks easy, you could just replace all the [ b]'s with <strong> and all the [/b]'s with </strong>. But if you want it to be right you need to make sure there is a matching closing tag for every open tag and vice versa. Otherwise you could break the rest of your layout. You also need to check if the tags are nested properly. I am sure there are other issues as well.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Begby posted:

This has been done a lot. It would probably be a good idea to check out the source for a php package that has already implemented this.

On the surface it looks easy, you could just replace all the [ b]'s with <strong> and all the [/b]'s with </strong>. But if you want it to be right you need to make sure there is a matching closing tag for every open tag and vice versa. Otherwise you could break the rest of your layout. You also need to check if the tags are nested properly. I am sure there are other issues as well.

It does get quite confusing quickly trying to keep track of matching tags, nested tags, etc.

What if I did the simple replace [ b] and [/b] with the corresponding html not paying any attention to if it's properly formatted at the end, and then use DOMDocument to correct any html problems?

For example, this code:
php:
<?
    $doc = new DOMDocument();
    $doc->loadHTML("<strong>test<i>italic");
    echo $doc->saveHTML();
?>
outputs this:

code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><strong>test<i>italic</i></strong></body></html>
Which has corrected the malformed html. Is this a bad solution?

Begby
Apr 7, 2005

Light saber? Check. Black boots? Check. Codpiece? Check. He's more machine than kid now.

fletcher posted:

Which has corrected the malformed html. Is this a bad solution?

It might be ok. Just test the ever living poo poo out of it with as much bad data as you can to make sure you get the desired results as you don't really know what is going on deep in the innards of DOMDocument.

That is a pretty good idea btw, good thinking.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


fletcher posted:

Which has corrected the malformed html. Is this a bad solution?

You could probably also use HTMLTidy to clean it up.

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

What kind of timestamps are these?

12314
12345
12356
12367
12378
12456
12859

Begby
Apr 7, 2005

Light saber? Check. Black boots? Check. Codpiece? Check. He's more machine than kid now.

drcru posted:

What kind of timestamps are these?

12314
12345
12356
12367
12378
12456
12859

Do you have any hints such as where you found these?

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

It's in a MySQL table that I don't have access to yet. All I have is a printout of what the table looks like.

duck monster
Dec 15, 2004

fletcher posted:

When I am validating fields submitted from a form I end up with a big if/else like:

php:
<?
if (!aValid) {
    //error information
} else {
    if (!bValid) {
        //error information
    } else {
        if (!cValid) {
            //error information
        } else {
            //db interaction
        }
    }
}?>
There's gotta be a better way than that. What's the right way to do this? Should the fields be validated by the setters of my class?

Heres another approach that I sometimes use

php:
<?
$errors = array(); $success = true;

if (!condition1) { $errors[] = "Condition 1 failed"; $success = false; }

if (!condition2) { $errors[] = "Condition 2 failed"; $success = false; }

if (!condition3) { $errors[] = "Condition 3 failed"; $success = false; }

if (!condition4) { $errors[] = "Condition 4 failed"; $success = false; }

if ($success) { 
           // Do stuff
} else {
   foreach ($errors as $error) {
          #Redraw the form and drop the errors into the template
   }
}
?>
It isn't as elegant as a validation array/loop thingo. And infact I'd strongly recomend building your own validation library where you can just pass it an array of validation data and have it spit out the goodness. You can then reuse it.

Or just find one on the net.

Another tip, not really php, is hunt down an old javascript library called 'fvalidate' for the javascript side of it. But remember NEVER rely on javascript validation. fvalidate is neat however, since it just involves setting alt tags on input fields. Setting the alt tags is kind of neat, since it validates, and normally alt tags have no real role on input fields, so they are handy for hijacking for metadata.

Treytor
Feb 8, 2003

Enjoy, uh... refreshing time!
I suck at PHP, I admit. All I really know how to do is modify code already given to me, and somewhat follow what is going on. Anyway, let me cut to the chase.

How do I do this:

code:
<?php
error_reporting(E_ALL);

echo "Testing....<br></br>";
$postData = array();
$postData['request_type'] = "PLAY_MSG";
$postData['destination'] = "1234567890";
$postData['file_name'] = "rr";
$postData['CID'] = "1234567890";
$postData['key'] = "1234";
$url = "http://www.server.com/handle_req.php";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$response = curl_exec($ch);
curl_close($ch);
if($response)
echo $response;
else
echo "Got no response";
?>
Without using curl, but fopen instead?

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


drcru posted:

What kind of timestamps are these?

12314
12345
12356
12367
12378
12456
12859

The roll-your-own kind. Good luck figuring out that system!

duck monster posted:

Another tip, not really php, is hunt down an old javascript library called 'fvalidate' for the javascript side of it. But remember NEVER rely on javascript validation. fvalidate is neat however, since it just involves setting alt tags on input fields. Setting the alt tags is kind of neat, since it validates, and normally alt tags have no real role on input fields, so they are handy for hijacking for metadata.

Alt tags on inputs are for screen readers. jQuery has a nice form validation plugin that uses class names or you can use JSON to build you validation requirements.

Treytor posted:

Without using curl, but fopen instead?

Edit: fopen is GET only, not POST, sorry. vv Learn something new all the time, that might come in handy.

duz fucked around with this message at 03:50 on Apr 1, 2008

waffle iron
Jan 16, 2004

Treytor posted:

I suck at PHP, I admit. All I really know how to do is modify code already given to me, and somewhat follow what is going on. Anyway, let me cut to the chase.

How do I do this:

code:
Without using curl, but fopen instead?
You're going to need to use stream_context_create() to create a context and use that with fopen.

http://us2.php.net/stream_context_create
http://us.php.net/manual/en/wrappers.http.php (See example 1)

Treytor
Feb 8, 2003

Enjoy, uh... refreshing time!
Thanks for the input. I was also told that something like this would work as well:
http://netevil.org/blog/2006/nov/http-post-from-php-without-curl

But I am having a hard time wrapping my head around what to do, exactly.
Like I said, I'm only into PHP about a week here, and I'm still trying to remember where to put the semicolons :(

edit: This is what I've got: (ignore the stupid echo's I have in there)
code:
<?php
error_reporting(E_ALL);

echo "Testing....<br></br>";
$postData = array();
echo "Building postData array<br></br>";
$postData['request_type'] = "PLAY_MSG";
$postData['destination'] = "1234567890";
$postData['file_name'] = "rr";
$postData['CID'] = "";
$postData['key'] = "";
$url = "http://www.server.com/takeit.php";

echo "Compiling array<br></br>";
$postData = http_build_query($postData);

echo "opts<br></br>";
$opts = array('http' =>
    array(
        'method'  => 'POST',
        'header'  => 'Content-type: application/x-www-form-urlencoded',
        'content' => $postData
    )
);

echo "stream context create<br></br>";
$context  = stream_context_create($opts);

echo "get result<br></br>";
$result = file_get_contents('http://www.server.com/takeit.php', false, $context);

if($result)
echo $result;
else
echo "Got no response";

?>
When I run that, I get this as a response:
code:
Testing....

Building postData array

Compiling array

opts

stream context create

get result

Got no response
after about 30 seconds (timeout).

What am I missing here? The original code works perfectly on a server that supports curl, but that isn't an option...

EDIT 2: It seems my server is being a bitch...

Treytor fucked around with this message at 04:58 on Apr 1, 2008

chips
Dec 25, 2004
Mein Führer! I can walk!
Question about PDFs:

Is there a way to get an image of a particular page in a PDF? I'm interested in adding PDF thumbnails to a website, but can't find any capacity in PHP for reading PDFs rather than just writing them.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

chips posted:

Question about PDFs:

Is there a way to get an image of a particular page in a PDF? I'm interested in adding PDF thumbnails to a website, but can't find any capacity in PHP for reading PDFs rather than just writing them.

Google found this: http://www.webmasterworld.com/forum88/898.htm which has someone trying to do the same, and info on how to do it. Requires imagemagick, looks like.

Adbot
ADBOT LOVES YOU

such a nice boy
Mar 22, 2002

chips posted:

Question about PDFs:

Is there a way to get an image of a particular page in a PDF? I'm interested in adding PDF thumbnails to a website, but can't find any capacity in PHP for reading PDFs rather than just writing them.

Shell out and use ghostscript:

code:
gs -q -sDEVICE=png256 -dBATCH -dNOPAUSE -dFirstPage=2 -dLastPage=2 -r300 -sOutputFile=test.png your.pdf
Tweak that device and page parameters as needed.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply