
Recherche avancée
Médias (91)
-
GetID3 - Boutons supplémentaires
9 avril 2013, par
Mis à jour : Avril 2013
Langue : français
Type : Image
-
Core Media Video
4 avril 2013, par
Mis à jour : Juin 2013
Langue : français
Type : Video
-
The pirate bay depuis la Belgique
1er avril 2013, par
Mis à jour : Avril 2013
Langue : français
Type : Image
-
Bug de détection d’ogg
22 mars 2013, par
Mis à jour : Avril 2013
Langue : français
Type : Video
-
Exemple de boutons d’action pour une collection collaborative
27 février 2013, par
Mis à jour : Mars 2013
Langue : français
Type : Image
-
Exemple de boutons d’action pour une collection personnelle
27 février 2013, par
Mis à jour : Février 2013
Langue : English
Type : Image
Autres articles (51)
-
Publier sur MédiaSpip
13 juin 2013Puis-je poster des contenus à partir d’une tablette Ipad ?
Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir -
Les autorisations surchargées par les plugins
27 avril 2010, parMediaspip core
autoriser_auteur_modifier() afin que les visiteurs soient capables de modifier leurs informations sur la page d’auteurs -
D’autres logiciels intéressants
12 avril 2011, parOn ne revendique pas d’être les seuls à faire ce que l’on fait ... et on ne revendique surtout pas d’être les meilleurs non plus ... Ce que l’on fait, on essaie juste de le faire bien, et de mieux en mieux...
La liste suivante correspond à des logiciels qui tendent peu ou prou à faire comme MediaSPIP ou que MediaSPIP tente peu ou prou à faire pareil, peu importe ...
On ne les connais pas, on ne les a pas essayé, mais vous pouvez peut être y jeter un coup d’oeil.
Videopress
Site Internet : (...)
Sur d’autres sites (7490)
-
file : Add an avoption for disabling truncating existing files on open
9 septembre 2012, par Martin Storsjöfile : Add an avoption for disabling truncating existing files on open
-
Working on images asynchronously
To get my quota on buzzwords for the day we are going to look at using ZeroMQ and Imagick to create a simple asynchronous image processing system. Why asynchronous ? First of all, separating the image handling from a interactive PHP scripts allows us to scale the image processing separately from the web heads. For example we could do the image processing on separate servers, which have SSDs attached and more memory. In this example making the images available to all worker nodes is left to the reader.
Secondly, separating the image processing from a web script can provide more responsive experience to the user. This doesn’t necessarily mean faster, but let’s say in a multiple image upload scenario this method allows the user to do something else on the site while we process the images in the background. This can be beneficial especially in cases where users upload hundreds of images at a time. To achieve a simple distributed image processing infrastructure we are going to use ZeroMQ for communicating between different components and Imagick to work on the images.
The first part we are going to create is a simple “Worker” -process skeleton. Naturally for a live environment you would like to have more error handling and possibly use pcntl for process control, but for the sake of brewity the example is barebones :
-
< ?php
-
-
define (’THUMBNAIL_ADDR’, ’tcp ://127.0.0.1:5000’) ;
-
define (’COLLECTOR_ADDR’, ’tcp ://127.0.0.1:5001’) ;
-
-
class Worker {
-
-
private $in ;
-
private $out ;
-
-
public function __construct ($in_addr, $out_addr)
-
{
-
$context = new ZMQContext () ;
-
-
$this->in = new ZMQSocket ($context, ZMQ: :SOCKET_PULL) ;
-
$this->in->bind ($in_addr) ;
-
-
$this->out = new ZMQSocket ($context, ZMQ: :SOCKET_PUSH) ;
-
$this->out->connect ($out_addr) ;
-
}
-
-
public function work () {
-
while ($command = $this->in->recvMulti ()) {
-
if (isset ($this->commands [$command [0]])) {
-
echo "Received work" . PHP_EOL ;
-
-
$callback = $this->commands [$command [0]] ;
-
-
array_shift ($command) ;
-
$response = call_user_func_array ($callback, $command) ;
-
-
if (is_array ($response))
-
$this->out->sendMulti ($response) ;
-
else
-
$this->out->send ($response) ;
-
}
-
else {
-
error_log ("There is no registered worker for $command [0]") ;
-
}
-
}
-
}
-
-
public function register ($command, $callback)
-
{
-
$this->commands [$command] = $callback ;
-
}
-
}
-
?>
The Worker class allows us to register commands with callbacks associated with them. In our case the Worker class doesn’t actually care or know about the parameters being passed to the actual callback, it just blindly passes them on. We are using two separate sockets in this example, one for incoming work requests and one for passing the results onwards. This allows us to create a simple pipeline by adding more workers in the mix. For example we could first have a watermark worker, which takes the original image and composites a watermark on it, passes the file onwards to thumbnail worker, which then creates different sizes of thumbnails and passes the final results to event collector.
The next part we are going to create a is a simple worker script that does the actual thumbnailing of the images :
-
< ?php
-
include __DIR__ . ’/common.php’ ;
-
-
// Create worker class and bind the inbound address to ’THUMBNAIL_ADDR’ and connect outbound to ’COLLECTOR_ADDR’
-
$worker = new Worker (THUMBNAIL_ADDR, COLLECTOR_ADDR) ;
-
-
// Register our thumbnail callback, nothing special here
-
$worker->register (’thumbnail’, function ($filename, $width, $height) {
-
$info = pathinfo ($filename) ;
-
-
$out = sprintf ("%s/%s_%dx%d.%s",
-
$info [’dirname’],
-
$info [’filename’],
-
$width,
-
$height,
-
$info [’extension’]) ;
-
-
$status = 1 ;
-
$message = ’’ ;
-
-
try {
-
$im = new Imagick ($filename) ;
-
$im->thumbnailImage ($width, $height) ;
-
$im->writeImage ($out) ;
-
}
-
catch (Exception $e) {
-
$status = 0 ;
-
$message = $e->getMessage () ;
-
}
-
-
return array (
-
’status’ => $status,
-
’filename’ => $filename,
-
’thumbnail’ => $out,
-
’message’ => $message,
-
) ;
-
}) ;
-
-
// Run the worker, will block
-
echo "Running thumbnail worker.." . PHP_EOL ;
-
$worker->work () ;
As you can see from the code the thumbnail worker registers a callback for ‘thumbnail’ command. The callback does the thumbnailing based on input and returns the status, original filename and the thumbnail filename. We have connected our Workers “outbound” socket to event collector, which will receive the results from the thumbnail worker and do something with them. What the “something” is depends on you. For example you could push the response into a websocket to show immediate feeedback to the user or store the results into a database.
Our example event collector will just do a var_dump on every event it receives from the thumbnailer :
-
< ?php
-
include __DIR__ . ’/common.php’ ;
-
-
$socket = new ZMQSocket (new ZMQContext (), ZMQ: :SOCKET_PULL) ;
-
$socket->bind (COLLECTOR_ADDR) ;
-
-
echo "Waiting for events.." . PHP_EOL ;
-
while (($message = $socket->recvMulti ())) {
-
var_dump ($message) ;
-
}
-
?>
The final piece of the puzzle is the client that pumps messages into the pipeline. The client connects to the thumbnail worker, passes on filename and desired dimensions :
-
< ?php
-
include __DIR__ . ’/common.php’ ;
-
-
$socket = new ZMQSocket (new ZMQContext (), ZMQ: :SOCKET_PUSH) ;
-
$socket->connect (THUMBNAIL_ADDR) ;
-
-
$socket->sendMulti (
-
array (
-
’thumbnail’,
-
realpath (’./test.jpg’),
-
50,
-
50,
-
)
-
) ;
-
echo "Sent request" . PHP_EOL ;
-
?>
After this our processing pipeline will look like this :
Now, if we notice that thumbnail workers or the event collectors can’t keep up with the rate of images we are pushing through we can start scaling the pipeline by adding more processes on each layer. ZeroMQ PUSH socket will automatically round-robin between all connected nodes, which makes adding more workers and event collectors simple. After adding more workers our pipeline will look like this :
Using ZeroMQ also allows us to create more flexible architectures by adding forwarding devices in the middle, adding request-reply workers etc. So, the last thing to do is to run our pipeline and see the results :
Let’s create our test image first :
$ convert magick:rose test.jpg
From the command-line run the thumbnail script :
$ php thumbnail.php Running thumbnail worker..
In a separate terminal window run the event collector :
$ php collector.php Waiting for events..
And finally run the client to send the thumbnail request :
$ php client.php Sent request $
If everything went according to the plan you should now see the following output in the event collector window :
array(4) [0]=> string(1) "1" [1]=> string(56) "
/test.jpg" [2]=> string(62) " /test_50x50.jpg" [3]=> string(0) "" Happy hacking !
-
-
Consent Mode v2 : Everything You Need to Know
7 mai 2024, par Alex — Analytics Tips