Closed Thread Icon

Topic awaiting preservation: ImageMagick, FreeBSD, and a nearly flying laptop...... (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=23866" title="Pages that link to Topic awaiting preservation: ImageMagick, FreeBSD, and a nearly flying laptop...... (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: ImageMagick, FreeBSD, and a nearly flying laptop...... <span class="small">(Page 1 of 1)</span>\

 
iconian
Nervous Wreck (II) Inmate

From: Perth, Western Austrlia
Insane since: Oct 2004

posted posted 10-31-2004 08:01

Gday all,
I have posted this to the ImageMagic forums as well but knowing how inteligent you guys are i thought i would ask here as well.

I have written a php gallery script which resises and crops an image to a square thumbnail, on my development machine (winxp pro, apache, mysql, php, and imagemagick win binaries) the script works as it should and can be seen here:
http://iconian.isa-geek.com/igal_r2/

But when i upload to my web host i just get a coded error response back as seen here:
http://www.iconiansolutions.com/igal_r2/

The web host is running freebsd and i have copied the binaries to the host, and changed the path in which the php looks for convert, but it doesnt seem to be executing it. I have checked and made sure exec() is enabled on the server and i have also tried system() and the other equivalents but still no joy. I have checked (using file_exists) and it tells me that convert is there but it doesnt do anything.

I am almost at the point of throwing the laptop through the window, and it is quite an expensive laptop please help me avoid doing so...

I should probably add the magick script isnt mine it is a modified version of a devweb tutorial, but it does work without a hitch on my xp development machine.

Matthew
www.iconiansolutions.com

matthew@iconiansolutions.com
www.iconiansolutions.com

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 10-31-2004 11:09

so...you uploaded the windows xp binaries to a free bsd machine?

iconian
Nervous Wreck (II) Inmate

From: Perth, Western Austrlia
Insane since: Oct 2004

posted posted 10-31-2004 13:02

no i uploaded the freebsd binaries to the freebsd machine.... i should have been more descriptive

Matthew

matthew@iconiansolutions.com
www.iconiansolutions.com

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 10-31-2004 14:03

Have you looked in your server logs to see if there's any errors there that might give you any insight to the problem? Also, try executing the size/crop part of your code on the command line and see what error messages you get if any. I was working through the same type of thing with netPBM once and both of these helped me get it working.

-Butcher-

iconian
Nervous Wreck (II) Inmate

From: Perth, Western Austrlia
Insane since: Oct 2004

posted posted 10-31-2004 14:29

thanks for the advice butcher Unfortunatley i dont have shell access to the server.....makes it hard, to the point where im considering building a server and upgrading my dsl so that i can host my own pages, but unfortunalty linux isnt one of my strong points and win server is a tad expensive....

But i will email the host and get the logs,

Matthew


matthew@iconiansolutions.com
www.iconiansolutions.com

(Edited by iconian on 10-31-2004 14:30)

ninmonkeys
Nervous Wreck (II) Inmate

From:
Insane since: May 2004

posted posted 10-31-2004 20:20
quote:
iconian said:

I should probably add the magick script isnt mine it is a modified version of a devweb tutorial, but it does work without a hitch on my xp development machine.

Can you post your script?

Without seeing the code, here's a few ideas:
-Are you using forward slashes for directory paths? (ie: /www/images/graphic.jpg )
-Does the script have read permission on the original file?
-Does the script have write permission on the thumbnail it creates?
-linux files are case-sensitive, maybe there is a typo in a filepath

iconian
Nervous Wreck (II) Inmate

From: Perth, Western Austrlia
Insane since: Oct 2004

posted posted 11-01-2004 06:18

Here is the code, first the config.php file that sets the file locations:

code:
<?php
$image_path = './images/';
$cache_path = './cache';
$convert_path = '/z1/iconian/public_html/convert';
$table_prefix ='igal_';
$site_name='Iconian Computer and Design Solutions';
$frame_prefix='drop';
?>



then the magic.php that actually handles the convert process:

code:
<?php
function imagemagick($filename,$command,$image_path,$cache_path,$convert_path)
{
// === CHECK INPUT =======================================================
// first, check if an image location is given
//if (!isset($_SERVER['PATH_INFO'])) {
// die('ERROR: No image specified.');
//}
//echo $_server['PATH_INFO'];

$image = $image_path.$filename;
//echo $image;
// next, check if the file exists
if (!file_exists($image)) {
die('ERROR: That image does not exist.');
}


// === PARSE COMMANDS ====================================================
// extract the commands from the query string
// eg.: ?resize(....)+flip+blur(...)
preg_match_all('/\+*(([a-z]+)(\(([^\)]*)\))?)\+*/',
$command,
$matches, PREG_SET_ORDER);

// concatenate commands for use in cache file name
$cache = $filename;
foreach ($matches as $match) {
$cache .= '_'.$match[2].'-'.$match[4];
}
$cache = str_replace('/','_',$cache);
$cache = $cache_path.'/'.$cache;
$cache = escapeshellcmd($cache);
//echo $cache.'<BR>';
// === RUN CONVERT =======================================================
//if (file_exists($convert_path)){
//echo 'success!';
//};
if (!file_exists($cache)) {
// there is no cached image yet, so we'll need to create it first

// convert query string to an imagemagick command string
$commands = '';
foreach ($matches as $match) {
// $match[2] is the command name
// $match[4] the parameter

// check input
if (!preg_match('/^[a-z]+$/',$match[2])) {
die('ERROR: Invalid command.');
}
if (!preg_match('/^[a-z0-9\/{}+-<>!@%]+$/',$match[4])) {
die('ERROR: Invalid parameter.');
}

// replace } with >, { with <
// > and < could give problems when using html
$match[4] = str_replace('}','>',$match[4]);
$match[4] = str_replace('{','<',$match[4]);

// check for special, scripted commands
switch ($match[2]) {
case 'colorizehex':
// imagemagick's colorize, but with hex-rgb colors
// convert to decimal rgb
$r = round((255 - hexdec(substr($match[4], 0, 2))) / 2.55);
$g = round((255 - hexdec(substr($match[4], 2, 2))) / 2.55);
$b = round((255 - hexdec(substr($match[4], 4, 2))) / 2.55);

// add command to list
$commands .= ' -colorize "'."$r/$g/$b".'"';
break;

case 'part':
// crops the image to the requested size
if (!preg_match('/^[0-9]+x[0-9]+$/',$match[4])) {
die('ERROR: Invalid parameter.');
}

list($width, $height) = explode('x', $match[4]);

// get size of the original
$imginfo = getimagesize($image);
$orig_w = $imginfo[0];
$orig_h = $imginfo[1];

// resize image to match either the new width
// or the new height

// if original width / original height is greater
// than new width / new height
if ($orig_w/$orig_h > $width/$height) {
// then resize to the new height...
$commands .= ' -resize "x'.$height.'"';

// ... and get the middle part of the new image
// what is the resized width?
$resized_w = ($height/$orig_h) * $orig_w;

// crop
$commands .= ' -crop "'.$width.'x'.$height.
'+'.round(($resized_w - $width)/2).'+0"';
} else {
// or else resize to the new width
$commands .= ' -resize "'.$width.'"';

// ... and get the middle part of the new image
// what is the resized height?
$resized_h = ($width/$orig_w) * $orig_h;

// crop
$commands .= ' -crop "'.$width.'x'.$height.
'+0+'.round(($resized_h - $height)/2).'"';
}
break;

case 'type':
// convert the image to this file type
if (!preg_match('/^[a-z]+$/',$match[4])) {
die('ERROR: Invalid parameter.');
}
$new_type = $match[4];
break;

default:
// nothing special, just add the command
if ($match[4]=='') {
// no parameter given, eg: flip
$commands .= ' -'.$match[2].'';
} else {
$commands .= ' -'.$match[2].' "'.$match[4].'"';
}
}
}

// create the convert-command
$convert = $convert_path.' '.$commands.' "'.$image.'" ';
if (isset($new_type)) {
// send file type-command to imagemagick
$convert .= $new_type.'-';
}

$convert .= '"'.$cache.'"';

// execute imagemagick's convert, save output as $cache
//echo "<B>".$convert."</b>";
exec($convert);

}

// === OUTPUT ============================================================
// there should be a file named $cache now
if (!file_exists($cache)) {
die('ERROR: Image conversion failed.');
}

// get image data for use in http-headers
$imginfo = getimagesize($cache);
$content_length = filesize($cache);
$last_modified = gmdate('D, d M Y H:i:s',filemtime($cache)).' GMT';

// array of getimagesize() mime types
$getimagesize_mime = array(1=>'image/gif',2=>'image/jpeg',3=>'image/png',
4=>'application/x-shockwave-flash',5=>'image/psd',
6=>'image/bmp',7=>'image/tiff',8=>'image/tiff',
9=>'image/jpeg',
13=>'application/x-shockwave-flash',
14=>'image/iff');

// did the browser send an if-modified-since request?
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
// parse header
$if_modified_since = preg_replace('/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE']);

if ($if_modified_since == $last_modified) {
// the browser's cache is still up to date
//header("HTTP/1.0 304 Not Modified");
//header("Cache-Control: max-age=86400, must-revalidate");
exit;
}
}

// send other headers
//header('Cache-Control: max-age=86400, must-revalidate');
//header('Content-Length: '.$content_length);
//header('Last-Modified: '.$last_modified);
if (isset($getimagesize_mime[$imginfo[2]])) {
//header('Content-Type: '.$getimagesize_mime[$imginfo[2]]);
} else {
// send generic header
header('Content-Type: application/octet-stream');
}

// and finally, send the image
return($cache);
};
?>



i have run

code:
if (file_exists($convert_path)){
echo 'success!';
};


on each of the files involved and they all come back success, except for the cached image of course. i have set the cache directory, the image directory and the directory the binaries in to chmod 777 to test and still not joy.

matthew@iconiansolutions.com
www.iconiansolutions.com

ninmonkeys
Nervous Wreck (II) Inmate

From:
Insane since: May 2004

posted posted 11-01-2004 18:13

Since it dies here, what is the output of $convert ?

quote:
if (!file_exists($cache)) {
// ... lots of code ...

// execute imagemagick's convert, save output as $cache

echo "<b>".$convert."</b>";

exec($convert);
}


// === OUTPUT ============================================================

// there should be a file named $cache now

if (!file_exists($cache)) {

die('ERROR: Image conversion failed.');

}
iconian
Nervous Wreck (II) Inmate

From: Perth, Western Austrlia
Insane since: Oct 2004

posted posted 11-02-2004 01:26

the output of convert is the following:

/z1/iconian/public_html/bin/convert -resize "130" -crop "130x130+0+42" "./images/starwars.jpg" "./cache/starwars.jpg_part-130x130"

matthew@iconiansolutions.com
www.iconiansolutions.com

« BackwardsOnwards »

Show Forum Drop Down Menu