Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP][GD] Efekt "rybiego oka" na zdjęciu
Forum PHP.pl > Forum > Przedszkole
patryk9200
Cześć,
Jak utworzyć efekt "rybiego oka" na zdjęciu wykorzystując bibliotekę GD ?
Jak również utworzyć coś w rodzaju falowania?

czy ktoś wie jak to zrobić??
abo uzyskać podobne efekty?
flashdev
Kiedys pisalem takie zabawki w różnych językach.
Masz tu coś w rodzaju JS:

Kod
// obraz zrodlowy oraz docelowy
// metody getPixel, oraz setPixel
source = new Image();
dest = new Image();

// wspolczynnik rybiego oka
factor = .7;
center = {x:width*.5, y:height*.5};
maxDist = dist(center.x, center.y);

for( i=0; i<width; i++){
    for( j=0; j<height; j++){
        angle = Math.atan2(j-center.y, i-center.x);
        newDist = mod(dist(i-center.x, j-center.y)/maxDist)*maxDist;
        color = source.getPixel(Math.sin(angle)*newDist, Math.cos(angle)*newDist);
        dest.setPixel(i, j, color);
    }
}

// funkcja przeksztalcajaca
// mozna zastosowac inna
function mod(x){
    return Math.pow(x, factor);
}

// oblicza dlugosc
function dist(x, y){
    return Math.sqrt(x*x+y*y);
}


Dodatkowo możesz pokusić się o interpolowanie pośrednich kolorów. Będzie dużo lepszy efekt.
I sprawdź czy nie ma gotowych bibliotek w php, takie operacje są bardzo powolne.
patryk9200
muszę to wykonać w PHP bo na podstawie tego chcę również zrobić captach'ę i znalazłem coś ciekawego:
http://www.fmwconcepts.com/imagemagick/bump/index.php
jak stworzyć coś takiego ?, mam bibliotekę Image Magick zainstalowaną na serwerze, tylko jak użyć ta funkcję?
erix
exec" title="Zobacz w manualu PHP" target="_manual i odpowiednia komenda na zapisanym na dysku obrazku.

Przykładowe parametry masz przecież podane...
patryk9200
czyli co mam zrobić coś takiego że do komenty exec();
mam wstawić to coś?
kod
  1. <?php
  2. [left] USAGE: bump [-t type] [-a amplitude] [-r radius] [-c center] [-m] [-b bgcolor] infile outfile
  3. USAGE: bump [-h or -help]         [/left]
  4.          [left]         -t .... type ............. type of bump shaping; choices are:
  5.         .......................... 1=sinusoid, 2=triangle; 3=circular; default=1
  6.         -a .... amplitude ........ amplitude or elevation of the bump; float;
  7.         .......................... positive raises the bump; negative lowers
  8.         .......................... the depression; default=10
  9.         -r .... radius ........... radius from center point determines the extent of the bump;
  10.         .......................... integer>=0; default is half the minimum image dimension
  11.         -c .... center ........... center point for the bump; center=cx,cy;
  12.          .......................... integer>=0; default is center of image
  13.         -m ....................... mask the outside of the radius with background color
  14.         -b .... bgcolor .......... background color for the masked area outside the radius         [/left]
  15.          [left]         PURPOSE: To apply a hemispherical-like bump distortion to an image.         [/left]
  16.          [left]         DESCRIPTION: BUMP applies a hemispherical-like bump distortion to an image.          The user can control the amplitude or height of the bump, the radius of          the bump, the center point of the bump and the type of displacement profile          used to control the shape of the bump. This is a simpler approximation of          my bubblewarp script that is much faster due to the use of -distort          polar/depolar and a displacement map.         [/left]
  17.          [left]         ARGUMENTS:          [/left]
  18.          [left]         -t type ... TYPE of displacement profile used to control the shape of the bump.          Choices are: 1=sinusoid, 2=triangle; 3=circular; default=1         [/left]
  19.          [left]         -a amplitude ... AMPLITUDE or elevation of the bump. Values are floats.          Postive values raise the bump and negative values lower the elevation.          A value of zero produces essentially no change. The default=10.         [/left]
  20.          [left]         -r radius ... RADIUS is the radial distance from the center point which         determines the extent of the bump. Values are integers>=0. The default is          half the minimum dimension of the image.         [/left]
  21.          [left]         -c center ... CENTER=cx,cy are the comma separated coordinates in the image          determining the center of the bump. Values are integers>=0. The default          is the center of the image.         [/left]
  22.          [left]         -m ... Enables a mask around the bump that is set to the desired background          color. This gives the result a spherical or bubble effect.         [/left]
  23.          [left]         -b bgcolor ... BGOLOR is the color of the masked area outside the bump.          Any valid IM color is allowed. See <a href=&#092;"http://imagemagick.org/script/color.php\" target=\"_blank\">http://imagemagick.org/script/color.php</a>         The default=black.         [/left]
  24.          [left]         NOTE: Requires IM 6.4.2-8 or higher due to the use of -distort polar/depolar.          [/left]
  25.          [left]         CAVEAT: No guarantee that this script will work on all platforms,          nor that trapping of inconsistent parameters is complete and          foolproof. Use At Your Own Risk.          [/left]
  26. ?>
erix
Nie... dry.gif

Np:
  1. <?php
  2. exec('bump -potrzebny -parametr');
  3. ?>

nie pakuj wszystkich biggrin.gif
patryk9200
a ten plik bump mam dać do katalogu gdzie go wykorzystuję?
erix
Nie. Jeśli piszesz, że masz na serwerze, to powinien on się bez problemu wywołać.
patryk9200
zrobiłem coś takiego:
kod
  1. <?php
  2. $filename = 'test.jpg';
  3. $filesavename = 'test2.jpg';
  4.  
  5. exec('bump $filename -a -20 $filesavename');
  6. ?>

ale mi to nie działa... błędów też nie wywala...

czy problemem mogą być scieżki? mam takie:
  1. <?php
  2. /usr/local/bin/php  /home/test/ftp/
  3. ?>
Crozin
A zobacz sobie:
  1. <?
  2.  
  3. $var = 'value';
  4.  
  5. echo '$var';
  6. echo "$var";
  7. ?>
patryk9200
Cytat(Crozin @ 27.07.2009, 15:26:25 ) *
A zobacz sobie:
  1. <?php
  2. $var = 'value';
  3.  
  4. echo '$var';
  5. echo &#092;"$var\";
  6. ?>

fakt zrobiłem gapę:P ale po poprawieniu ' ' na " " i tak nie działa...
Crozin
A co zwraca exec" title="Zobacz w manualu PHP" target="_manual? Jakiś komunikat?
patryk9200
właśnie nic...
erix
A wykonanie tego polecenia na istniejących plikach z konsoli czymś skutkuje?
Crozin
Pokaż cały Twój obecny kod.
patryk9200
robiłem na wiele sposobów i żaden nie zadziałał... oto kod:
  1. <?php
  2. $file['directory'] = '/images/';
  3. $file['dirsave'] = '/captcha/';
  4. $filename = './test.jpg';
  5. $filesavename = './test2.jpg';
  6.  
  7.  
  8.  
  9. exec("-bump $filename -a -20 $filesavename");
  10. $var = 'value';
  11.  
  12.  
  13. $path2im = '/usr/local/bin/convert';
  14. exec ("/usr/local/bin/convert -bump  -a -20 $filename  $filesavename");
  15.  
  16. $sourcepath = './test.jpg';
  17. $destpath = './test2.jpg';
  18. $path2im = '/usr/local/bin/convert';
  19. exec (' -bump  -a -20 ' . $sourcepath . ' ' . $destpath);
  20. ?>
golaod
Trochę ciężko ocenić czy exec coś zwraca skoro mu się nawet nie każe zwracać.

  1. <?php
  2. $exec = 'twoje komendy ktore wpisujesz tutaj 2>&1';
  3.        
  4. exec( $exec, $output );
  5.  
  6. print_r( $output );
  7. ?>
Crozin
Jakbyś popatrzył do manuala to byś zauważył, że exec" title="Zobacz w manualu PHP" target="_manual() jako drugi i trzeci parametr przyjmują zmienne, do których zostanie zwrócony komunikat. Użyj tego i pokaż nam co zostało zwrócone.
patryk9200
dziwne... zwróciło tylko Array ( )...
golaod
Pisałem wyżej... musisz dodać na końcu 2>&1
patryk9200
wyskoczył komunikat: Array ( [0] => sh: bump: command not found )...

gdy zrobiłem coś takiego:
  1. <?php
  2. $exec = " /home/test/ftp/test/ADMIN/CLASS/bump  -a -20 $filename  $filesavename  2>&1";
  3.      
  4. exec( $exec, $output );
  5.  
  6. print_r( $output );
  7. ?>

to wyskoczyło:
Array ( [0] => sh: /home/test/ftp/test/ADMIN/CLASS/bump: /bin/bash: bad interpreter: Brak dostępu )

strona jest na nazwa.pl

skoro nie rozpoznaje komendy, a plik bump gdy daje do katalogu to pisze brak dostępu to może go wrzucić do cgi-bin/ ?
czy tak to zadziała? a może da się jakoś własną wersję ImageMagic zainstalować?
Fifi209
Jak nie masz dostępu to musisz zmienić chmody...
patryk9200
gdy zrobiłem coś takiego:
  1. <?php
  2. $filename = './test.jpg';
  3. $filesavename = './test2.jpg';
  4. $exec = &#092;"  /home/test/ftp/test/ADMIN/CLASS/bump -bump -a -20 $filename  $filesavename  2>&1\";
  5.    
  6. exec( $exec, $output );
  7.  
  8. print_r( $output );
  9. ?>


wyskoczyło mi:
  1. <?php
  2. Array (     [0] =>      [1] => --- UNKNOWN OPTION ---     [2] =>      [3] =>      [4] => bump:     [5] =>      [6] => USAGE: bump [-t type] [-a amplitude] [-r radius] [-c center] [-m] [-b bgcolor] infile outfile     [7] => USAGE: bump [-h or -help]     [8] =>      [9] => OPTIONS:     [10] =>      [11] => -t      type               type of bump shaping; choices are:     [12] =>                            1=sinusoid, 2=triangle; 3=circular; default=1     [13] => -a      amplitude          amplitude or elevation of the bump; float;     [14] =>                            positive raises the bump; negative lowers     [15] =>                            the depression; default=10     [16] => -r      radius             radius from center point determines the extent of the bump;     [17] =>                            integer>=0; default is half the minimum image dimension     [18] => -c      center             center point for the bump; center=cx,cy;     [19] =>                            integer>=0; default is center of image     [20] => -m                         mask the outside of the radius with background color     [21] => -b      bgcolor            background color for the masked area outside the radius     [22] =>  )
  3. ?>


co robię źle?
erix
Widocznie podałeś nieistniejący parametr.
patryk9200
gdy zrobiłem coś takiego:
  1. <?php
  2. $filename = '/test.jpg';
  3. $filesavename = 'test2.jpg';
  4. $exec = "/home/test/ftp/test/ADMIN/CLASS/bump $filename -bump -a -20 -c 75,75   $filesavename  2>&1";
  5. exec( $exec, $output );
  6. print_r( $output );
  7. ?>

wyskoczyło mi:
  1. <?php
  2. Array (     [0] => convert: unrecognized option `-quiet'.     [1] =>      [2] => --- FILE /test.jpg DOES NOT EXIST OR IS NOT AN ORDINARY FILE, NOT READABLE OR HAS ZERO SIZE ---     [3] =>      [4] =>      [5] => bump:     [6] =>      [7] => USAGE: bump [-t type] [-a amplitude] [-r radius] [-c center] [-m] [-b bgcolor] infile outfile     [8] => USAGE: bump [-h or -help]     [9] =>      [10] => OPTIONS:     [11] =>      [12] => -t      type               type of bump shaping; choices are:     [13] =>                            1=sinusoid, 2=triangle; 3=circular; default=1     [14] => -a      amplitude          amplitude or elevation of the bump; float;     [15] =>                            positive raises the bump; negative lowers     [16] =>                            the depression; default=10     [17] => -r      radius             radius from center point determines the extent of the bump;     [18] =>                            integer>=0; default is half the minimum image dimension     [19] => -c      center             center point for the bump; center=cx,cy;     [20] =>                            integer>=0; default is center of image     [21] => -m                         mask the outside of the radius with background color     [22] => -b      bgcolor            background color for the masked area outside the radius     [23] =>  )
  3. ?>


plik test.jpg ma chmod 0777
erix
Czytasz, co się do Ciebie pisze? Zawsze tak wywali, gdy użyjesz któregoś z nieistniejących parametrów albo pomylisz składnię.

Zresztą, popatrz:
Cytat
convert: unrecognized option `-quiet'.
patryk9200
Cytat(erix @ 27.07.2009, 22:48:04 ) *
Czytasz, co się do Ciebie pisze? Zawsze tak wywali, gdy użyjesz któregoś z nieistniejących parametrów albo pomylisz składnię.

Zresztą, popatrz:


bo argumenty przepisałem z strony więc raczej nie powinno być błędów, po drugie nie wiem czemu pisze " FILE /test.jpg DOES NOT EXIST OR IS NOT AN ORDINARY FILE, NOT READABLE OR HAS ZERO SIZE"
skoro plik istnieje i ma chmod 0777, po trzecie kombinuje już od kilku godzin i nic...
Crozin
Hmmm co to za pomysł na wrzucanie plików na: / ?
Nie wiem dlaczego, ale mam przeczucie, że ten plik jest pod ./...jpg nie /...jpg
patryk9200
jak dam ./ to wyskakuje to samo, a zdjęcie jest w tym samym folderze co skrypt bump...
erix
Kod
/test.jpg

Slesz na początku szuka w drzewie Unix (katalog root), a nie w katalogu głównym Twojego konta.
patryk9200
czy komendy pisałem w dobrej kolejnosci?
Crozin
Cytat
Kod
USAGE: bump [-t type] [-a amplitude] [-r radius] [-c center] [-m] [-b bgcolor] infile outfile
Masz napiasne jak używać tego programu.
patryk9200
zrobiłem tak:
  1. <?php
  2. $exec = "/home/test/ftp/test/ADMIN/CLASS/bump bump [-a 20] $filename $filesavename  2>&1";
  3. exec( $exec, $output );
  4. print_r( $output );
  5. ?>

i wyskakuje mi:
  1. <?php
  2. Array (     [0] => convert: unrecognized option `-quiet'.     [1] =>      [2] => --- FILE bump DOES NOT EXIST OR IS NOT AN ORDINARY FILE, NOT READABLE OR HAS ZERO SIZE ---     [3] =>      [4] =>      [5] => bump:     [6] =>      [7] => USAGE: bump [-t type] [-a amplitude] [-r radius] [-c center] [-m] [-b bgcolor] infile outfile     [8] => USAGE: bump [-h or -help]     [9] =>      [10] => OPTIONS:     [11] =>      [12] => -t      type               type of bump shaping; choices are:     [13] =>                            1=sinusoid, 2=triangle; 3=circular; default=1     [14] => -a      amplitude          amplitude or elevation of the bump; float;     [15] =>                            positive raises the bump; negative lowers     [16] =>                            the depression; default=10     [17] => -r      radius             radius from center point determines the extent of the bump;     [18] =>                            integer>=0; default is half the minimum image dimension     [19] => -c      center             center point for the bump; center=cx,cy;     [20] =>                            integer>=0; default is center of image     [21] => -m                         mask the outside of the radius with background color     [22] => -b      bgcolor            background color for the masked area outside the radius     [23] =>  )
  3. ?>

a gy zrobię tak:
  1. <?php
  2. $exec = " bump [-a 20] $filename $filesavename  2>&1";
  3. exec( $exec, $output );
  4. print_r( $output );
  5. ?>

to wyskakuje ze nie zna takiej komendy...
erix
Kod
convert: unrecognized option `-quiet'.     [1] =>      [2] => --- FILE bump DOES NOT EXIST OR IS NOT AN ORDINARY FILE, NOT READABLE OR HAS ZERO SIZE ---     [3] =>

Nie widzisz, jakie są błedy...?

Proponowałbym liznąć odrobinę podstaw Unixów, konkretnie konsoli, bo już krążymy w kółko...
patryk9200
już zrobiłem na innej zasadzie działa i nie kożysta już z bump. Smiga, że hooo winksmiley.jpg mam tokena podobnego do tego z google tongue.gif
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.