Conditions | 4 |
Paths | 8 |
Total Lines | 73 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
Bugs | 3 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
41 | public function ResampleImage($parent, $imgs, $k, $data, $dpi = 72) |
||
42 | { |
||
43 | \Storage::disk($parent->storageDisk)->put($parent->local_path.'word/media/'.$imgs[$k]['img_file_src'], $data); |
||
44 | |||
45 | //rework img to new size and jpg format |
||
46 | $img_rework = \Image::make($parent->StoragePath($parent->local_path.'word/media/'.$imgs[$k]['img_file_src'])); |
||
47 | if($dpi!=72) $img_rework2 = \Image::make($parent->StoragePath($parent->local_path.'word/media/'.$imgs[$k]['img_file_src'])); |
||
48 | |||
49 | $imgWidth = $img_rework->width(); |
||
50 | $imgHeight = $img_rework->height(); |
||
51 | |||
52 | //check https://startbigthinksmall.wordpress.com/2010/01/04/points-inches-and-emus-measuring-units-in-office-open-xml/ |
||
53 | // for EMUs calculation |
||
54 | /* |
||
55 | 295px @72 dpi = 1530350 EMUs = Multiplier for 72dpi pixels 5187.627118644067797 |
||
56 | 413px @72 dpi = 2142490 EMUs = Multiplier for 72dpi pixels 5187.627118644067797 |
||
57 | */ |
||
58 | $availableWidth = (int) ($imgs[$k]['cx'] / 5187.627118644067797); |
||
59 | $availableHeight = (int) ($imgs[$k]['cy'] / 5187.627118644067797); |
||
60 | |||
61 | //height based resize |
||
62 | $h = (($imgHeight / $imgWidth) * $availableWidth); |
||
63 | $w = (($imgWidth / $imgHeight) * $h); |
||
64 | |||
65 | //if height based resize has too large width, do width based resize |
||
66 | if ($h > $availableHeight) { |
||
67 | $w = (($imgWidth / $imgHeight) * $availableHeight); |
||
68 | $h = (($imgHeight / $imgWidth) * $w); |
||
|
|||
69 | } |
||
70 | |||
71 | $h = null; |
||
72 | |||
73 | //for getting non high dpi measurements, as the document is on 72 dpi. |
||
74 | //TODO: this should be improved. it does not really need the resampling to identify the new sizes. |
||
75 | //instead this should just be calculated, as resampling the image is too process instensive. |
||
76 | $img_rework->resize($w, $h, function ($constraint) { |
||
77 | $constraint->aspectRatio(); |
||
78 | $constraint->upsize(); |
||
79 | }); |
||
80 | $new_height = $img_rework->height(); |
||
81 | $new_width = $img_rework->width(); |
||
82 | |||
83 | if($dpi!=72) |
||
84 | { |
||
85 | //for storing the image in high dpi, so it has good quality on high dpi screens |
||
86 | $img_rework2->resize(((int)$w*($dpi/72)), $h, function ($constraint) { // make high dpi version for actual storage |
||
87 | $constraint->aspectRatio(); |
||
88 | $constraint->upsize(); |
||
89 | }); |
||
90 | $img_rework2->save($parent->StoragePath($parent->local_path.'word/media/'.$imgs[$k]['img_file_dest'])); |
||
91 | |||
92 | //set dpi of image to high dpi |
||
93 | /*$im = new \imagick(); |
||
94 | $im->setResolution($dpi,$dpi); |
||
95 | $im->readImage($parent->StoragePath($parent->local_path.'word/media/'.$imgs[$k]['img_file_dest'])); |
||
96 | $im->writeImage($parent->StoragePath($parent->local_path.'word/media/'.$imgs[$k]['img_file_dest'])); |
||
97 | $im->clear(); |
||
98 | $im->destroy(); |
||
99 | */ |
||
100 | } |
||
101 | else { |
||
102 | $img_rework->save($parent->StoragePath($parent->local_path.'word/media/'.$imgs[$k]['img_file_dest'])); |
||
103 | } |
||
104 | |||
105 | $parent->zipper->folder('word/media')->add($parent->StoragePath($parent->local_path.'word/media/'.$imgs[$k]['img_file_dest'])); |
||
106 | |||
107 | return [ |
||
108 | 'height' => $new_height, |
||
109 | 'width' => $new_width, |
||
110 | 'height_emus' => (int) ($new_height * 5187.627118644067797), |
||
111 | 'width_emus' => (int) ($new_width * 5187.627118644067797), |
||
112 | ]; |
||
113 | } |
||
114 | } |
||
115 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.