Get width and height of quicktime clip (.mov) with php? - php

I need to get the width and height of a .mov-file with php.
How do I do that?

I have used getid3 in the past to achieve this you can grab it from http://www.getid3.org/ I am not sure how well maintained it is anymore
You could knock up some code to look similar to this
<?php
include_once('getid3.php');
$getID3 = new getID3;
$file = './file.mov';
$file_analysis = $getID3->analyze($file);
echo 'Video Resolution = '.$file_analysis['video']['resolution_x'].' X '.$file_analysis['video']['resolution_y'];
?>

Related

Cut corners in image PHP

Im working with Intervention Image to make a frame. Now im stuck on a part to cut off the edges. I need 4 of those images to make them fit as a frame. I know i can use the Intervention Image library to rotate the image, but i have no clue to cut those corners. Anyone has a idea how to achieve this?
Original:
Result:
You need to create two polygons and fill them with transparent colors.
http://image.intervention.io/api/polygon
An example:
$img = Image::make('foo/bar/baz.jpg')->encode('png');
$w = $img->width();
$h = $img->height();
$points = [0,0,$width,0,$width,$width,0,0];
$img->polygon($points, function($d) {
$d->background("transparent");
});
$points = [0,$height,$width,$height,$width,$height-$width,0,$height];
$img->polygon($points, function($d) {
$d->background("transparent");
});
$img->save('foo/bar/baz_cut.png'); // jpg won't have transparency

Rotate, Crop image using Guillotine plugin and Laravel 5 Intervention

I work on image editor module, using guillotine plugin.
I get parameters from ajax.
{angle: 0,h: 600,scale: 6.7811,w: 800,x: 0,y: 485}
In laravel I have this code
$img = \Input::get('img');
$data = \Input::get('data');
$image = \Image::make($img)->rotate((int)$data['angle']);
// crop image
$image->crop((int)$data['w'], (int)$data['h'], (int)$data['x'], (int)$data['y']);
$image->save('uploads/tmp/img.png');
The code is working , but the result is not the same as the user selected area.
I guess I need to use 'scale' attribute too, but I don't know how.
For example : user selected area
Result
I appreciate your help! :)
you need to use the scale factor
then multiply it by the image width by using the widen() function, it:
Resizes the current image to new width, constraining aspect ratio
so the height will also get scale
$img = \Input::get('img');
$data = \Input::get('data');
list($type, $img) = explode(';', $img);
list(, $img) = explode(',', $img);
$img = base64_decode($img);
// save image
$img = file_put_contents('uploads/tmp/img.png', $img);
$image = \Image::make('uploads/tmp/img.png')->rotate((float)$data['angle']);
//we get the image width then multiply it by the scale factor, it will also scale the height automatically
$image->widen((int)$image->width()*$data['scale']);
// crop image
$image->crop((int)$data['w'], (int)$data['h'], (int)$data['x'], (int)$data['y']);
$image->save('uploads/tmp/img.png');

Get large facebook video thumbnail using graph

I want to get the large facebook video thumbnail using graph. Below code get the small thumbnail
https://graph.facebook.com/VIDEO_ID/picture
This code will return Ex:
https://fbcdn-vthumb-a.akamaihd.net/hvthumb-ak-prn1/632393_10151574602254838_10151574598089838_34404_282_t.jpg
If i replace "t" with "n" i will get the large image
https://fbcdn-vthumb-a.akamaihd.net/hvthumb-ak-prn1/632393_10151574602254838_10151574598089838_34404_282_n.jpg
But how do i get it using facebook graph or replace "t" with "n" using php
Thanks in advance.
you can use this php code, its working for me.
<?php
$video_id = "10153231379946729";
$xml = file_get_contents('http://graph.facebook.com/' . $video_id);
$result = json_decode($xml);
$small = $result->format[0]->picture;
$medium = $result->format[1]->picture;
//fetch the 720px sized picture
$large = $result->format[3]->picture;
?>
<img src="<?php echo $medium;?>">

Add image dimensions automatically to <img>

I scored my website on gtmetrix.com.
It recommends adding image dimensions to all my images. The thing is, I need some way of adding these automatically, so if the image changes, the dimentions are updated.
What I have
<img src="bla.png">
What I'd like to have
<img src="bla.png" width="{width of image}" height="{height of img}">
Is there a php way or a jquery way to do this?
For a wordpress site.
PHP:
<?php
list($width, $height) = getimagesize("bla.png");
echo "<img src='bla.png' width='$width' height='$height'>";
?>
You can use image onload event to calculate the dimensions of image. Pure javascript approach, something like ;
var image = new Image();
image.onload = function()
{
//after load complete you will get the image dimensions here from
//image.width and image.height
}
image.src = 'image url';
In php it's getimagesize($file) if you are outputting images dynamically.
You should do it with PHP not with javascript. If you add it with jQuery / javascript, the width and height would be added after loading. The main reason of specifying width and height is to let the engine render the page faster. It would not be of any help if it as added after loading.
You can use the index 3 of the returned array from getimagesize() directly in the image tag. It contains a string with height="yyy" width="xxx" an can be used directly in an IMG tag.
<?php
list($width, $height, $type, $attr) = getimagesize("file.png");
echo "<img src='file.png' $attr />";
?>
You can visit http://php.net/manual/en/function.getimagesize.php for more details on this function.

Get image height that is not in content

I am building a custom wordpress theme and have a slideshow on the front page displaying images from blog posts.
Now if the image is over 300px in height I want to force its widthand center it vertically. So my question is:
Is there a way, in php or javascript to get the height of an image by only using the URL of the image?
EDIT: I tried this: <?php list($height) = getimagesize(echo catch_that_image()); echo "<p>$height</p>"; ?> where catch_that_image() returns the URL, but somehow this doesn't work (I think the first echo breaks it). Any ideas?
Thank you for your help.
image by only using the URL of the image?
var img = new Image();
img.onload = function() {
alert('The size is ' + this.width + 'x' + this.height);
};
img.src = 'some image URL';
Try it
http://jsfiddle.net/NPSMN/
ps:
I tried this: ... where
catch_that_image() returns the URL, but somehow this doesn't work (I
think the first echo breaks it). Any ideas?
did you look closer at your code? echo outputs to the browser, not to the argument of the function.
<?php
list(,$height) = getimagesize(catch_that_image());
echo "<p>$height</p>";
?>
See getimagesize() in PHP. That will do what you're looking for.
http://php.net/manual/en/function.getimagesize.php
<?php
$url = "http://www.example.com/image.jpg";
list($width, $height) = getimagesize($url);
echo "Width: $width<br />Height: $height";
?>

Categories