-
-
Save sumonst21/10dfeebdf88f2422ccf390eaa6d7f081 to your computer and use it in GitHub Desktop.
Resize plex metadata images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$a = new img_resize(); | |
$a->run(); | |
class img_resize { | |
public $img_files = array(); | |
public $img_path = ""; | |
public $bad_files = array(); | |
public $img_pix_limit = 921600; // 1280*720 | |
public function __construct() { | |
$this->img_path = getcwd(); | |
$this->img_path = '/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Metadata/'; | |
} | |
public function run() { | |
$this->_get_images(); | |
$this->_resize_images(); | |
print_r($this->bad_files); | |
} | |
private function _resize_images() { | |
foreach ($this->img_files as $img_file) { | |
$mogrify_out = array(); | |
$cmd_resize = sprintf("mogrify -resize 921600@ '%s'", $img_file); | |
exec($cmd_resize,$mogrify_out,$mogrify_ret); | |
if ($mogrify_ret == 0) { | |
print sprintf("info: successfully resized:[%s]\n",basename($img_file)); | |
$this->img_convert_success[] = $img_file; | |
} else { | |
$this->img_convert_fail[] = $img_file; | |
} | |
} | |
} | |
private function _get_images() { | |
$cmd = sprintf("find '%s' -type f -size +400k",$this->img_path); | |
exec($cmd,$found,$ret); | |
if ($ret == 0) { | |
foreach ($found as $file) { | |
$identify_data = array(); | |
$cmd_identify = sprintf("identify '%s'",$file); | |
exec($cmd_identify,$identify_data,$identify_ret); | |
if ($identify_ret == 0) { | |
// JPEG 1920x1080 | |
if (preg_match("/.*JPEG\s([\d]{1,})x([\d]{1,})\s.*/",$identify_data[0],$identify_m)) { | |
$tmp_px_size = $identify_m[1]*$identify_m[2]; | |
if ( $tmp_px_size > $this->img_pix_limit ) { | |
print sprintf("info: [%s] size:[%sx%s] Needs resizing: [%s > %s]\n",basename($file), $identify_m[1], $identify_m[2], $tmp_px_size, $this->img_pix_limit); | |
$this->img_files[] = $file; | |
} | |
} else { | |
$this->bad_files[] = $file; | |
} | |
} else { | |
$this->bad_files[] = $file; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment