Skip to content

Commit 8c137df

Browse files
committed
bump SixLabors to latest
resolves #1144
1 parent 3ba514a commit 8c137df

File tree

4 files changed

+36
-30
lines changed

4 files changed

+36
-30
lines changed

src/Peachpie.Library.Graphics/Exif.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static PhpArray exif_read_data(Context ctx, string filename, string secti
9797
//array.Add("FileDateTime", (int)File.GetCreationTime(filename).ToOADate());
9898
array.Add("FileSize", (int)bytes.Length);
9999

100-
IImageInfo image;
100+
ImageInfo image;
101101

102102
using (var ms = new MemoryStream(bytes))
103103
{
@@ -374,22 +374,20 @@ public static PhpString exif_thumbnail(Context ctx, string filename, PhpAlias wi
374374
return default(PhpString);
375375

376376
// get thumbnail from <filename>'s content:
377-
using (var ms = new MemoryStream(bytes))
377+
try
378378
{
379-
try
379+
//using (var image = Image.Load(bytes.AsSpan()))
380380
{
381381
// TODO: Image.Identify needs a new overload that returns the format.
382-
using (var image = Image.Load(ms, out format))
383-
{
384-
// return byte[] ~ image.MetaData.ExifProfile{ this.data, this.thumbnailOffset, this.thumbnailLength }
385-
thumbnail = image.Metadata.ExifProfile.CreateThumbnail<Rgba32>();
386-
}
387-
}
388-
catch
389-
{
390-
return default(PhpString);
382+
var imageInfo = Image.Identify(bytes.AsSpan());
383+
// return byte[] ~ image.MetaData.ExifProfile{ this.data, this.thumbnailOffset, this.thumbnailLength }
384+
imageInfo.Metadata.ExifProfile.TryCreateThumbnail<Rgba32>(out thumbnail);
391385
}
392386
}
387+
catch
388+
{
389+
return default(PhpString);
390+
}
393391

394392
if (thumbnail == null)
395393
{

src/Peachpie.Library.Graphics/Peachpie.Library.Graphics.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
<Description>Peachpie PHP language library functions for image processing.</Description>
1010
</PropertyGroup>
1111
<ItemGroup>
12-
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.8" />
13-
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0" />
14-
<PackageReference Include="SixLabors.Fonts" Version="1.0.1" />
12+
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.10" />
13+
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="2.1.6" />
14+
<PackageReference Include="SixLabors.Fonts" Version="2.1.3" />
1515
</ItemGroup>
1616

1717
<ItemGroup>

src/Peachpie.Library.Graphics/PhpGd2.cs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ public static PhpResource imagecreatetruecolor(int x_size, int y_size)
447447
return img;
448448
}
449449

450-
static PhpGdImageResource imagecreatecommon(int x_size, int y_size, IConfigurationModule configuration, IImageFormat format)
450+
static PhpGdImageResource imagecreatecommon(int x_size, int y_size, IImageFormatConfigurationModule configuration, IImageFormat format)
451451
{
452452
if (x_size <= 0 || y_size <= 0)
453453
{
@@ -472,7 +472,9 @@ public static PhpResource imagecreatefromstring(byte[] image)
472472

473473
try
474474
{
475-
return new PhpGdImageResource(Image.Load<Rgba32>(image, out var format), format);
475+
return new PhpGdImageResource(
476+
Image.Load<Rgba32>(image.AsSpan())
477+
);
476478
}
477479
catch
478480
{
@@ -562,35 +564,35 @@ public static PhpResource imagecreatefromxpm(Context ctx, string filename)
562564
return imagercreatefromfile(ctx, filename);
563565
}
564566

565-
static PhpGdImageResource imagercreatefromfile(Context ctx, string filename, IConfigurationModule formatOpt = null)
567+
static PhpGdImageResource imagercreatefromfile(Context ctx, string filename, IImageFormatConfigurationModule formatOpt = null)
566568
{
567569
if (string.IsNullOrEmpty(filename))
568570
{
569571
PhpException.Throw(PhpError.Warning, Resources.filename_cannot_be_empty);
570572
return null;
571573
}
572574

573-
var configuration = (formatOpt == null)
574-
? Configuration.Default
575-
: new Configuration(formatOpt);
575+
var decoderOptions = (formatOpt == null)
576+
? new DecoderOptions()
577+
: new DecoderOptions() { Configuration = new Configuration(formatOpt) }
578+
;
576579

577580
Image<Rgba32> img = null;
578-
IImageFormat format = null;
579-
581+
580582
using (var stream = Utils.OpenStream(ctx, filename))
581583
{
582584
if (stream != null)
583585
{
584586
try
585587
{
586-
img = Image.Load<Rgba32>(configuration, stream, out format);
588+
img = Image.Load<Rgba32>(decoderOptions, stream);
587589
}
588590
catch { }
589591
}
590592
}
591593

592594
return (img != null)
593-
? new PhpGdImageResource(img, format)
595+
? new PhpGdImageResource(img)
594596
: null;
595597
}
596598

@@ -1264,7 +1266,13 @@ static bool imagecopy(PhpResource dst_im, PhpResource src_im, int dst_x, int dst
12641266
.Crop(new Rectangle(src_x, src_y, src_w, src_h))
12651267
.Resize(new Size(src_w, src_h))))
12661268
{
1267-
dst.Image.Mutate(o => o.DrawImage(cropped, opacity: opacity, location: new Point(dst_x, dst_y)));
1269+
dst.Image.Mutate<Rgba32>(
1270+
o => o.DrawImage(
1271+
cropped,
1272+
opacity: opacity,
1273+
backgroundLocation: new Point(dst_x, dst_y)
1274+
)
1275+
);
12681276
}
12691277
}
12701278
catch (Exception ex)
@@ -1320,7 +1328,7 @@ public static bool imagegd(PhpResource im)
13201328
return imagesave(ctx, im, to, (img, stream) =>
13211329
{
13221330
// use the source's encoder:
1323-
var encoder = img.GetConfiguration().ImageFormatsManager.FindEncoder(GifFormat.Instance) as GifEncoder;
1331+
var encoder = img.Configuration.ImageFormatsManager.GetEncoder(GifFormat.Instance) as GifEncoder;
13241332

13251333
// or use default encoding options
13261334
encoder ??= new GifEncoder(); // TODO: ColorTableMode from allocated colors count?

src/Peachpie.Library.Graphics/PhpGdImageResource.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ private PhpGdImageResource()
7070
{
7171
}
7272

73-
internal PhpGdImageResource(int x, int y, IConfigurationModule configuration, IImageFormat format)
73+
internal PhpGdImageResource(int x, int y, IImageFormatConfigurationModule configuration, IImageFormat format)
7474
: this(new TImage(new Configuration(configuration), x, y), format)
7575
{
7676
}
7777

7878
/// <summary>
7979
/// Creates PhpGdImageResource without creating internal image.
8080
/// </summary>
81-
internal PhpGdImageResource(TImage/*!*/image, IImageFormat format)
81+
internal PhpGdImageResource(TImage/*!*/image, IImageFormat format = null)
8282
: this()
8383
{
8484
Debug.Assert(image != null);
@@ -88,7 +88,7 @@ internal PhpGdImageResource(TImage/*!*/image, IImageFormat format)
8888

8989
//
9090
_image = image;
91-
_format = format;
91+
_format = format ?? image.Metadata.DecodedImageFormat;
9292
}
9393

9494
static void RemoveFramesRange(TImage/*!*/image, int from, int count)

0 commit comments

Comments
 (0)