LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Converting a Script from SHELL to PHP (http://www.linuxquestions.org/questions/programming-9/converting-a-script-from-shell-to-php-622433/)

gcclinux 02-20-2008 03:28 AM

Converting a Script from SHELL to PHP
 
Hello,

I have changed ISP and now I can no longer use PHP system call to call my shell script, so I was wondering if anyone could help me convert it to PHP.

Code:


--------------------------------------------------------------------
First Script is:
--------------------------------------------------------------------

#!/bin/bash
#
# A simple BASH script to use ImageMagick to create a pretty thumbnail
# from the source image as well as scaling the original and placing them
# both in the correct folders.
# name = make_thumb.sh
#
set -x

# Ensure that /usr/local/bin is in the PATH, as ICDSoft removed it without
# notice :o(
export PATH=$PATH:/usr/local/bin

SRC=$1
NAME=$2
DOT=/home/PATH/inc/dot.jpg
TEMP=/home/PATH/www/tmp/$$.jpg

function FN_shadow
{
  FSP=$1
  SRC_SIZE=`identify $FSP | cut -f3 -d' '`
  convert -scale ${SRC_SIZE}!  -border 9x9 -bordercolor white $DOT $TEMP
  mogrify -blur 7x7 $TEMP
  composite -geometry +7+6 $FSP $TEMP $FSP
  chmod 666 $FSP
}

ORIGINAL=/home/PATH/www/photos/originals/$NAME
THUMB=/home/PATH/www/photos/thumbs/$NAME

# Resize image to correct directories
convert -scale 478x358 -border 1x1 -bordercolor black "$SRC" $ORIGINAL
convert -scale 118x118 -border 1x1 -bordercolor black "$SRC" $THUMB
FN_shadow $ORIGINAL
FN_shadow $THUMB

--------------------------------------------------------------------
Second Script is:
--------------------------------------------------------------------



#!/bin/bash
#
# A simple BASH script to use ImageMagick to create rotate an original
# image, and then regenerate the thumbnail.
# name = rotate.sh
#
#set -x

# Ensure that /usr/local/bin is in the PATH, as ICDSoft removed it without
# notice :o(
export PATH=$PATH:/usr/local/bin

SRC=$1
DEGREE=$2
DOT=/home/PATH/inc/dot.jpg
TEMP=/home/PATH/www/tmp/$$.jpg

function FN_shadow
{
  FSP=$1
  SRC_SIZE=`identify $FSP | cut -f3 -d' '`
  convert -scale ${SRC_SIZE}!  -border 9x9 -bordercolor white $DOT $TEMP
  mogrify -blur 7x7 $TEMP
  composite -geometry +7+6 $FSP $TEMP $FSP
  chmod 666 $FSP
}

function FN_rotate
{
  FSP=$1
  RESX=`identify $FSP | cut -f3 -d' ' | sed 's/^\([^x]*\).*/\1/g'`
  RESY=`identify $FSP | cut -f3 -d' ' | sed 's/^[^x]*x\([^+]*\).*/\1/g'`
  mogrify -crop $(($RESX-18))x$(($RESY-18))+7+6 -rotate $DEGREE "$FSP"
  FN_shadow $FSP
}

ORIGINAL=/home/PATH/www/photos/originals/$SRC
THUMB=/home/PATH/www/photos/thumbs/$SRC

# Rotate thumbnail and original
FN_rotate $ORIGINAL
FN_rotate $THUMB

If anyone could help me I would be very much appreciated!

Regards,

Ricardo

rubadub 02-20-2008 10:00 AM

you can use imagemagick directly from php, here's the title page with a list of the available functions, http://uk3.php.net/manual/en/ref.imagick.php, on the other hand you could use the GD library if imagemagick isn't available on your isp...

gcclinux 02-21-2008 05:08 AM

Thanks for your response, unfortunately I can no longer any system calls so imagemagick is not a option, I need to be using the GD library, but I would not know how to convert my script to php using GD as I lost contact with the PHP guy that helped me build the page.

Any help would be much appreciated.

learnq 02-21-2008 05:51 AM

sent email to you.


All times are GMT -5. The time now is 06:57 PM.