Menu principale:
php -v
~ → php -v PHP 7.1.7 (cli) (built: Jul 15 2017 18:08:09) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
php -r 'echo "hello world";' hello world%
echo "hello world" | php hello world%
php file.php
php resize.php /path/to/image.jpg /save/to/directory/
<?php var_dump($argc, $argv);
php resize.php /path/to/image.jpg /save/to/directory/ int(3) array(3) { [0]=> string(10) "resize.php" [1]=> string(18) "/path/to/image.jpg" [2]=> string(19) "/save/to/directory/" }
if ($argc != 3) { die('Numero di parametri non corretto'); } list($scriptName, $imagePath, $destinationPath) = $argv;
$handle = imagecreatefromjpeg($imagePath); $size = min(imagesx($handle), imagesy($handle)); $imageCropped = imagecrop($handle, [ 'x' => 0, 'y' => 0, 'width' => $size, 'height' => $size, ]); $destinationImage = sprintf('%s/image_%s.jpg', $destinationPath, rand(0, 100)); imagejpeg($imageCropped, $destinationImage);
<?php if ($argc != 3) { die('Numero di parametri non corretto'); } list($scriptName, $imagePath, $destinationPath) = $argv; if (!file_exists($imagePath)) { die('Immagine non trovata'); } if (!is_writable($destinationPath)) { die('Directory di destinazione non scrivibile'); } $handle = imagecreatefromjpeg($imagePath); $size = min(imagesx($handle), imagesy($handle)); $imageCropped = imagecrop($handle, [ 'x' => 0, 'y' => 0, 'width' => $size, 'height' => $size, ]); $destinationImage = sprintf('%s/image_%s.jpg', $destinationPath, rand(0, 100)); imagejpeg($imageCropped, $destinationImage);