
Advanced search
Other articles (16)
-
Publier sur MédiaSpip
13 June 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 -
Taille des images et des logos définissables
9 February 2011, byDans beaucoup d’endroits du site, logos et images sont redimensionnées pour correspondre aux emplacements définis par les thèmes. L’ensemble des ces tailles pouvant changer d’un thème à un autre peuvent être définies directement dans le thème et éviter ainsi à l’utilisateur de devoir les configurer manuellement après avoir changé l’apparence de son site.
Ces tailles d’images sont également disponibles dans la configuration spécifique de MediaSPIP Core. La taille maximale du logo du site en pixels, on permet (...) -
Supporting all media types
13 April 2011, byUnlike most software and media-sharing platforms, MediaSPIP aims to manage as many different media types as possible. The following are just a few examples from an ever-expanding list of supported formats: images: png, gif, jpg, bmp and more audio: MP3, Ogg, Wav and more video: AVI, MP4, OGV, mpg, mov, wmv and more text, code and other data: OpenOffice, Microsoft Office (Word, PowerPoint, Excel), web (html, CSS), LaTeX, Google Earth and (...)
On other websites (4539)
-
configure: Avoid requiring c99wrap for working around msys path issues
14 November 2013, by Martin Storsjöconfigure: Avoid requiring c99wrap for working around msys path issues
Msys is unable to convert unix style absolute paths to windows style
paths when combined with certain multichar MSVC options such asFo<file>. We used to work around this issue by passing them as two
separate parameters separated by a space to c99wrap, which then mapped
them back to the actual parameter format that MSVC uses.The only paths that actually are an issue are absolute unix style
paths, and the only place such absolute paths are used with the output
arguments (-Fo, -Fe, -Fi, -out:) are for the temp files within configure.By setting TMPDIR to . for msvc/icl builds, we never need to use
absolute unix style paths for the file output, and we can use the
actual proper form of the file output parameters. This avoids requiring
the c99wrap wrapper for remapping the parameters for cases where the
c99 converter isn’t invoked at all (MSVC2013 and ICL).Signed-off-by: Martin Storsjö <martin@martin.st>
-
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!
-
-
doc: update the documentation generator to match the new website
13 July 2014, by db0