Wie verwende ich die pigjar API?

Die pigjar API kann sehr einfach über HTTP POST angesprochen werden. Das dabei resultierende Ergebnisobjekt kann in verschiedenen Formaten (json, xml, wddx) angefordert werden.

CURL

Das folgende Beispiel benötigt das CURL Command Line Utility.

$ curl -L http://www.pigjar.com/api/image/format/json -F "image=@my_image.png"	

PHP mit pecl/http

Das folgende Beispiel in PHP benötigt die PECL HTTP Extension.

<?php
	$opts = array("redirect" => 1);
	$file = array("name" => "image", "type" => "image/png", "file" => "my_image.png");
	$resp = http_post_fields(
		"http://www.pigjar.com/api/image/format/json",
		array(),
		array($file),
		$opts
	);
	print_r($resp);

	$body = http_parse_message($resp)->body;
	print_r($body);

	$json = json_decode($body);
	print_r($json);
?>	

PHP mit ext/curl

Das folgende Beispiel in PHP benötigt die libCURL Extension.

<?php
	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, "http://www.pigjar.com/api/image/format/json");
	curl_setopt($curl, CURLOPT_POST, true);
	curl_setopt($curl, CURLOPT_POSTFIELDS, array("image" => "@my_image.png"));
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
	$body = curl_exec($curl);
	$json = json_decode($body);
?>	

Ergebnisobjekt

Das Ergebnisobjekt, in den Beispielen als JSON (format/json) angefordert, hält folgende Attribute:

{
	uid:       'die UID des Uploads',

	href:      'der pigjar Share Link',
	html:      'HTML Code der das Thumbnail zur pigjar Share Seite verlinkt',
	bbcode:    'BBCode für z.B. Foren als [URL=...][IMG]...[/IMG][/URL]',

	thumbUrl:  'URL zum Thumbnail',
	imageUrl:  'URL zum Bild',
	delUrl:    'eindeutige URL zum Löschen des Uploads',

	thumbDim:  'Dimensionen des Thumbnails in Pixel, Breite x Höhe (200x150)',
	imageDim:  'Dimensionen des Originals in Pixel, Breite x Höhe',

	thumbSize: 'Größe des Thumbnails in Bytes',
	imageSize: 'Größe des Bildes in Bytes'
}	
Werbung