@@ -33,10 +33,25 @@ public static string GetCropUrl(this MediaWithCrops mediaWithCrops, string cropA
33
33
return mediaWithCrops . GetCropUrl ( imageUrlGenerator , cropAlias : cropAlias , useCropDimensions : true ) ;
34
34
}
35
35
36
- [ Obsolete ( "This method does not get the crops or cache buster value from the media item." ) ]
36
+ [ Obsolete ( "Use the GetCropUrl overload with the updated parameter order and note this implementation has changed to get the URL from the media item." ) ]
37
37
public static string GetCropUrl ( this IPublishedContent mediaItem , string cropAlias , IImageUrlGenerator imageUrlGenerator , ImageCropperValue imageCropperValue )
38
38
{
39
- return mediaItem . Url ( ) . GetCropUrl ( imageUrlGenerator , imageCropperValue , cropAlias : cropAlias , useCropDimensions : true ) ;
39
+ return mediaItem . GetCropUrl ( imageCropperValue , cropAlias , imageUrlGenerator ) ;
40
+ }
41
+
42
+ /// <summary>
43
+ /// Gets the crop URL by using only the specified <paramref name="imageCropperValue" />.
44
+ /// </summary>
45
+ /// <param name="mediaItem">The media item.</param>
46
+ /// <param name="imageCropperValue">The image cropper value.</param>
47
+ /// <param name="cropAlias">The crop alias.</param>
48
+ /// <param name="imageUrlGenerator">The image URL generator.</param>
49
+ /// <returns>
50
+ /// The image crop URL.
51
+ /// </returns>
52
+ public static string GetCropUrl ( this IPublishedContent mediaItem , ImageCropperValue imageCropperValue , string cropAlias , IImageUrlGenerator imageUrlGenerator )
53
+ {
54
+ return mediaItem . GetCropUrl ( imageUrlGenerator , imageCropperValue , true , cropAlias : cropAlias , useCropDimensions : true ) ;
40
55
}
41
56
42
57
/// <summary>
@@ -134,7 +149,7 @@ public static string GetCropUrl(
134
149
ImageCropRatioMode ? ratioMode = null ,
135
150
bool upScale = true )
136
151
{
137
- return mediaItem . GetCropUrl ( imageUrlGenerator , null , width , height , propertyAlias , cropAlias , quality , imageCropMode , imageCropAnchor , preferFocalPoint , useCropDimensions , cacheBuster , furtherOptions , ratioMode , upScale ) ;
152
+ return mediaItem . GetCropUrl ( imageUrlGenerator , null , false , width , height , propertyAlias , cropAlias , quality , imageCropMode , imageCropAnchor , preferFocalPoint , useCropDimensions , cacheBuster , furtherOptions , ratioMode , upScale ) ;
138
153
}
139
154
140
155
public static string GetCropUrl (
@@ -154,28 +169,31 @@ public static string GetCropUrl(
154
169
ImageCropRatioMode ? ratioMode = null ,
155
170
bool upScale = true )
156
171
{
157
- return mediaWithCrops . MediaItem . GetCropUrl ( imageUrlGenerator , mediaWithCrops . LocalCrops , width , height , propertyAlias , cropAlias , quality , imageCropMode , imageCropAnchor , preferFocalPoint , useCropDimensions , cacheBuster , furtherOptions , ratioMode , upScale ) ;
172
+ if ( mediaWithCrops == null ) throw new ArgumentNullException ( nameof ( mediaWithCrops ) ) ;
173
+
174
+ return mediaWithCrops . Content . GetCropUrl ( imageUrlGenerator , mediaWithCrops . LocalCrops , false , width , height , propertyAlias , cropAlias , quality , imageCropMode , imageCropAnchor , preferFocalPoint , useCropDimensions , cacheBuster , furtherOptions , ratioMode , upScale ) ;
158
175
}
159
176
160
177
private static string GetCropUrl (
161
178
this IPublishedContent mediaItem ,
162
179
IImageUrlGenerator imageUrlGenerator ,
163
180
ImageCropperValue localCrops ,
164
- int ? width ,
165
- int ? height ,
166
- string propertyAlias ,
167
- string cropAlias ,
168
- int ? quality ,
169
- ImageCropMode ? imageCropMode ,
170
- ImageCropAnchor ? imageCropAnchor ,
171
- bool preferFocalPoint ,
172
- bool useCropDimensions ,
173
- bool cacheBuster ,
174
- string furtherOptions ,
175
- ImageCropRatioMode ? ratioMode ,
176
- bool upScale )
181
+ bool localCropsOnly ,
182
+ int ? width = null ,
183
+ int ? height = null ,
184
+ string propertyAlias = Constants . Conventions . Media . File ,
185
+ string cropAlias = null ,
186
+ int ? quality = null ,
187
+ ImageCropMode ? imageCropMode = null ,
188
+ ImageCropAnchor ? imageCropAnchor = null ,
189
+ bool preferFocalPoint = false ,
190
+ bool useCropDimensions = false ,
191
+ bool cacheBuster = true ,
192
+ string furtherOptions = null ,
193
+ ImageCropRatioMode ? ratioMode = null ,
194
+ bool upScale = true )
177
195
{
178
- if ( mediaItem == null ) throw new ArgumentNullException ( " mediaItem" ) ;
196
+ if ( mediaItem == null ) throw new ArgumentNullException ( nameof ( mediaItem ) ) ;
179
197
180
198
var cacheBusterValue = cacheBuster ? mediaItem . UpdateDate . ToFileTimeUtc ( ) . ToString ( CultureInfo . InvariantCulture ) : null ;
181
199
@@ -184,8 +202,8 @@ private static string GetCropUrl(
184
202
185
203
var mediaItemUrl = mediaItem . MediaUrl ( propertyAlias : propertyAlias ) ;
186
204
187
- // Only get crops when used
188
- if ( imageCropMode == ImageCropMode . Crop || imageCropMode == null )
205
+ // Only get crops from media when required and used
206
+ if ( localCropsOnly == false && ( imageCropMode == ImageCropMode . Crop || imageCropMode == null ) )
189
207
{
190
208
// Get the default cropper value from the value converter
191
209
var cropperValue = mediaItem . Value ( propertyAlias ) ;
0 commit comments